-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