打印char多维阵列无法正常工作
#include <stdio.h>
int main()
{
FILE *fisier;
fisier = fopen("cnp.txt", "r");
int cnpuri = 0;
char cnp[10][13];
while(1){
fscanf(fisier, "%s", cnp[cnpuri]);
cnpuri++;
if(feof(fisier))
break;
}
int i;
for(i = 0; i < cnpuri; i++){
printf("%s \n", cnp[i]);
}
fclose(fisier);
return 0;
}
这是我正在阅读的文本:
1234567890123
1763578126765
4156156546489
5749684631654
5498654168763
这就是它在终端中显示的内容:
12345678901231763578126765415615654648957496846316545498654168763
1763578126765415615654648957496846316545498654168763
415615654648957496846316545498654168763
57496846316545498654168763
5498654168763
#include <stdio.h>
int main()
{
FILE *fisier;
fisier = fopen("cnp.txt", "r");
int cnpuri = 0;
char cnp[10][13];
while(1){
fscanf(fisier, "%s", cnp[cnpuri]);
cnpuri++;
if(feof(fisier))
break;
}
int i;
for(i = 0; i < cnpuri; i++){
printf("%s \n", cnp[i]);
}
fclose(fisier);
return 0;
}
This is the text I'm reading:
1234567890123
1763578126765
4156156546489
5749684631654
5498654168763
And this is what it shows in terminal:
12345678901231763578126765415615654648957496846316545498654168763
1763578126765415615654648957496846316545498654168763
415615654648957496846316545498654168763
57496846316545498654168763
5498654168763
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于,阵列的第二尺寸
不足以存储输入字符串的终端零特征。
至少像这样声明它
也可以更改以下方式
The problem is that the second size of the array
is not large enough to store the terminating zero character of entered strings.
Declare it at least like
Also change the while loop the following way