gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 07:20:45 25 4
gpt4 key购买 nike

<分区>

我是 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);
}
}

我正在运行这样的脚本:./a.out < 数字.in

目前我的脚本返回完全不同的数字!我在这里做错了什么?文件是否将它们作为字符发送,所以我需要以某种方式转换为整数? (我尝试保存为字符,然后将字符转换为整数,也得到了奇怪的数字——但不同的奇怪数字!)

已解决,分号使用错误 >_<

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com