-3
我的代碼,以輸出一串A的此塊到一個文件(500行的500 A的)輸出字符陣列產生奇怪的符號
int main() {
FILE * output = fopen("somefile.txt", "w");
//initialize string
char s[500];
for(int i = 0;i < 500;i++) {
//set each letter to 'A'
s[i] = 'A';
}
for(int i = 0;i < 500;i++) {
//output the string 500 times
fprintf(output, "%s\n", s);
}
}
然而,在是一個反向「^」每行的結尾。 (screenshot here)
我該如何擺脫它?
C字符串(是的,這是C),需要用一個空字符終止。 –
您應該null終止As的字符串。使用'char s [501] = {0};' – sameerkn
哦,它工作:) – Frodakcin