我想知道我的代码有什么问题。我通常使用scanf,但我试图得到fgets的窍门。但是,当我尝试打印一个char数组,其中数组的每个元素都在一个单独的行上,但即使我将该数组的限制定义为任意高数字,它也只有十一行的限制。我是一名初学者程序员,所以尽量尽可能简单。打印字符数组
#include <stdio.h>
#define max_line 4096
int main(void) {
char str[max_line];
printf("Enter string: ");
fgets(str, max_line, stdin);
for (int i=0;i <max_line && i!='\n'; i++) {
printf("%c\n", str[i]);
}
return 0;
}
我想得到这样的结果。
Enter string: Hello
H
e
l
l
o
但事实证明,完全不同
Enter string: Hello
H
e
l
l
o
/n //Sorry, I don't know how to add new lines in stackoverflow, but I think you get the idea.
/n
/n
/n
/n
'我= '\ n'' - >'STR [1]!=' \ n'' – BLUEPIXY
所以在我的病情,我只是改变它对? – danielwestfall
为什么'我!='\ n''? Comeon,三思! ;-)你想要测试什么*不是新行? – alk