Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从fscanf-int转换接收到奇怪的数字?_C_Scanf - Fatal编程技术网

从fscanf-int转换接收到奇怪的数字?

从fscanf-int转换接收到奇怪的数字?,c,scanf,C,Scanf,我对C很陌生,这里有个问题。我正试图通过下面的脚本传递文件numbers.in。numbers.in包含以下两行: 12,34,56789 123456,789,0123 我试图识别逗号的描述 #include <stdio.h> void main(int argc, char *argv[]) { int p ,n ,x ; //Converted ints. while ( fscanf(stdin,"%d,%d,%d\n",&p,&am

我对C很陌生,这里有个问题。我正试图通过下面的脚本传递文件numbers.in。numbers.in包含以下两行:

12,34,56789
123456,789,0123
我试图识别逗号的描述

#include <stdio.h>
void main(int argc, char *argv[])
{      
  int   p ,n ,x ;   //Converted ints.

  while ( fscanf(stdin,"%d,%d,%d\n",&p,&n,&x) == 3 );
  {
    printf("got the sequence (%d,%d,%d)\n",x,p,n);
  }
}
#包括
void main(int argc,char*argv[])
{      
int p,n,x;//已转换的int。
而(fscanf(stdin、%d、%d\n、&p、&n、&x)==3);
{
printf(“获取序列(%d,%d,%d)\n”,x,p,n);
}
}
我运行的脚本如下所示: ./a.out 目前我的脚本返回完全不同的数字!我做错了什么?文件是否将它们作为字符发送,因此我需要以某种方式转换为整数?(我尝试将字符另存为字符,然后将字符转换为整数,还得到了奇怪的数字——但不同的奇怪数字!)


已解决,分号用法错误>.
while(fscanf(stdin,“%d,%d\n”,&p,&n,&x)==3)<代码>while(fscanf(stdin,“%d,%d,%d\n”,&p,&n,&x)==3)<代码>while(fscanf(stdin,“%d,%d,%d\n”,&p,&n,&x)==3)<代码>while(fscanf(stdin,“%d,%d,%d\n”,&p,&n,&x)==3);脚本返回什么数字?请删除while后面的分号。:)脚本返回什么数字?请删除while后面的分号。:)脚本返回什么数字?请删除while后面的分号。:)脚本返回什么数字?请删除while后面的分号。:)天哪!多么尴尬的哈哈,你说得对,这就解决了它!(将在8分钟内接受你的回答)哦,我的天哪!多么尴尬的哈哈,你说得对,这就解决了它!(将在8分钟内接受你的回答)哦,我的天哪!多么尴尬的哈哈,你说得对,这就解决了它!(将在8分钟内接受你的回答)哦,我的天哪!多么尴尬的哈哈,你说得对,这就解决了它!(将在8分钟内接受您的回答)
  while ( fscanf(stdin,"%d,%d,%d\n",&p,&n,&x) == 3 ); <-- remove this semicolon