一个反转字符串的程序。 [英] A program to reverse a string.
本文介绍了一个反转字符串的程序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个程序,当给出一个字符串时,它会将其打印回来。
这是我的程序。注意我是C中的biginner。
I''m trying to write a program that when given a string it prints it back whats.
here is my program.Note I''m a biginner in C.
展开 | 选择 | Wrap | 行号
推荐答案
该代码有很多错误。
- 反向在使用之前未声明,并且被错误定义:它不带0个参数。正确的声明是
void reverse(char * input);这应该出现在main()之前。- 缺少main()的返回类型:" int main()"不是main()
- 第13行:您不能声明一个在编译时未知的大小的数组。改为使用malloc()。
- 第3行:char input [];你不能声明这样的数组,除非你在声明它时初始化它,在这种情况下编译器可以填写所需的大小,比如char str [] =" hello" ;.使用char输入[80];或类似的东西,如果你不希望用户输入超过80个字符的字符串。
There are many errors with that code.
- reverse is not declared before it is used and is wrongly defined: it does not take 0 arguments. The correct declaration is
void reverse(char * input); and this should appear before main().- Return type for main() is missing: "int main()" not "main()"
- line 13: you can not declare an array with a size that is not known at compile time. Use malloc() instead.
- line 3: char input[]; you cannot declare an array like this unless you initialize it when you declare it in which case the the compiler can fill in the size required, like char str[] = "hello";. Use char input[80]; or something like this instead if you don''t expect the user to input strings longer than 80 characters.
>
你应该在反向数组中放置终止零。
You should place terminating zero in the reversed array.
非常感谢,现在我知道我在哪里犯了错误。
Thank you very much, now I know where I made errors.
该代码有很多错误。
- 反向在使用之前未声明,并且被错误定义:它不带0个参数。正确的声明是
void reverse(char * input);这应该出现在main()之前。- 缺少main()的返回类型:" int main()"不是main()
- 第13行:您不能声明一个在编译时未知的大小的数组。改为使用malloc()。
- 第3行:char input [];你不能声明这样的数组,除非你在声明它时初始化它,在这种情况下编译器可以填写所需的大小,比如char str [] =" hello" ;.使用char输入[80];或类似的东西,如果你不希望用户输入超过80个字符的字符串。
这篇关于一个反转字符串的程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文