【发布时间】:2017-07-18 06:46:59
【问题描述】:
我编写了一个程序来计算文件中的字符数。我打算让程序不区分大小写。但我得到一个错误打印如下。
#include <stdio.h>
#include <string.h>
int main() {
FILE *fp1;
char c[100], f[20], k;
int count = 0;
printf("Enter the file name\n");
scanf("%s", f);
printf("Enter the character to be counted\n");
scanf(" %c", &k);
fp1 = fopen(f, "r");
while (fscanf(fp1, "%c", c) != EOF) {
if (strcmpi(c, k) == 0)
count++;
}
fclose(fp1);
printf("File '%s' has %d instances of letter %c", f, count, k);
return 0;
}
在这个程序中我收到一个错误提示
warning: passing argument 2 of 'strcmpi' makes pointer from integer without a cast [-Wint-conversion]
我能做些什么来纠正它?
【问题讨论】:
-
提示:
c和k的数据类型(或者只是“类型”)不一样。 -
如果您使用
fgetc一次读取一个字符,这个程序可以更容易编写。 -
您可以使用
tolower和toupper将一个字符变为小写/大写。 -
我不知道为什么你甚至需要 strcmpi 函数,如果你只是比较字符只是直接比较字符这绝对是矫枉过正 一次获取一个字符通常比较它,即
c==k -
而
strcmpi绝对是non-standard