【发布时间】:2015-03-20 15:28:17
【问题描述】:
我是 C 编程新手。我正在尝试逐行从文件中获取输入并打印每行的长度。 这是我的代码-
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char name[100];
printf("Enter file name\n");
scanf("%s",name);
FILE * input;
input=fopen(name,"r");
char line[100];
fscanf(input,"%s",line);
while(!feof(input))
{
printf("%d\n",strlen(line));
fscanf(input,"%s",line);
}
return 0;
}
这是我的输入文件-
172.24.2.1
172.24.2.225
172.17.4.41
172.24.4.42
202.16.112.150
172.24.152.10
这是correctly 打印每行的长度。但是在编译过程中我收到了这个警告-
In function ‘main’:
main.c:24:4: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘size_t’ [-Wformat=]
printf("%d\n",strlen(line));
所以我的问题是,尽管我的输出是正确的,但为什么我会收到此警告,我该如何解决这个问题? 提前致谢。
【问题讨论】:
-
简单的答案是错误消息会告诉您确切的问题 -
(size_t != int)
标签: c