[英]How can I read integer from file with cmd in c
This is input.txt
这是
input.txt
5343
232
5
int main(int argc, char *argv[]) {
int x;
int sum=0;
int count=0;
if(argc==1)
printf("Error message!");
if(argc>=2)
{
FILE* file = fopen (argv[1], "r");
while(!feof(file)){
fscanf(file,"%d",&x);
sum+=x;
count++;
}
printf("%d", sum);
printf("%d", count);
return 0;
}
I use this main and write this in cmd= c_file.exe input.txt我用这个main,把这个写在cmd=c_file.exe input.txt
After that statement in cmd, there is no output and I can't write anything in cmd. cmd那条语句之后,就没有output了,cmd什么也写不出来。
input.txt is given above I want to read and store the integer digit by digit how can I do it?上面给出了input.txt我想逐位读取和存储integer我该怎么做?
while(fscanf(file,"%d",&x) == 1)
{
sum+=x;
count++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.