Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/143.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/4/c/71.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
C++ 从文件读取输入时,我的C程序无法正确读取整数。有什么建议吗?_C++_C - Fatal编程技术网

C++ 从文件读取输入时,我的C程序无法正确读取整数。有什么建议吗?

C++ 从文件读取输入时,我的C程序无法正确读取整数。有什么建议吗?,c++,c,C++,C,我有一个文本文件,我应该用文件输入/输出技术读取: 47900 31007 34500 9100 57984 14822 这是我的密码: #include <stdio.h> FILE *input; int CA1; int CA2; int CA3; int CL1; int CL2; int CL3; int main (void) { input = fopen("c:\\class\\currentrati

我有一个文本文件,我应该用文件输入/输出技术读取:

47900       31007
34500        9100
57984       14822
这是我的密码:

#include <stdio.h>

 FILE *input;
 int CA1;
 int CA2;
 int CA3;
 int CL1;
 int CL2;
 int CL3;


int main (void)
{
    input = fopen("c:\\class\\currentratio.txt","r");
    fscanf(input,"%d %d\n", &CA1, &CL1);
    fscanf(input, "%d %d\n", &CA2, &CL2);
    fscanf(input, "%d %d\n", &CA3, &CL3);
    printf("%d", &CA1);
    fclose(input);
    return 0;
}
#包括
文件*输入;
int CA1;
int-CA2;
int CA3;
int CL1;
int-CL2;
int CL3;
内部主(空)
{
输入=fopen(“c:\\class\\currentratio.txt”,“r”);
fscanf(输入,“%d%d\n”、&CA1、&CL1);
fscanf(输入,“%d%d\n”、&CA2和&CL2);
fscanf(输入,“%d%d\n”、&CA3、&CL3);
printf(“%d”和&CA1);
fclose(输入);
返回0;
}
当我打印数字时,它们是

4229680、4229704、4229744、4229712、4229664和4229720


谢谢大家的帮助。

您正在打印变量的地址,而不是它的值。
去掉地址:
printf(“%d”,CA1)

另一件事,您没有检查,如果文件打开成功,您应该处理它,尤其是在某些事情不起作用的情况下

if(!input)
{
    printf("Could not open the file specified.");
    return -1;
}

您正在打印变量的地址,而不是它的值。
去掉地址:
printf(“%d”,CA1)

另一件事,您没有检查,如果文件打开成功,您应该处理它,尤其是在某些事情不起作用的情况下

if(!input)
{
    printf("Could not open the file specified.");
    return -1;
}

你实际使用的是哪种语言?使用
printf(“%d”、&CA1)标记该语言,而不是其他语言
您试图打印变量
CA1
的地址,而不是值。尝试删除
&
字符;)此外,尝试使用
-Wall
等标志编译代码,以显示警告消息(如果有)。例如,您的代码编译时带有一个格式警告:
code.c:17:3:警告:格式“%d”要求参数类型为“int”,但参数2的类型为“int*”[-Wformat=]printf(“%d”,&CA1)
您实际使用的是哪种语言?使用
printf(“%d”、&CA1)标记该语言,而不是其他语言
您试图打印变量
CA1
的地址,而不是值。尝试删除
&
字符;)此外,尝试使用
-Wall
等标志编译代码,以显示警告消息(如果有)。例如,您的代码编译时带有格式警告:
code.c:17:3:警告:格式“%d”要求参数类型为“int”,但参数2的类型为“int*”[-Wformat=]printf(“%d”,&CA1)