我想知道我的代碼有什麼問題。我通常使用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