我正在用 C 编程,我开始做一些基本的编程,比如文件中的字数,但不幸的是,我的程序执行存在缺陷。gcc 编译器会显示这样的警告:
test.c: In function ‘main’:
test.c:11: warning: passing argument 1 of ‘fopen’ makes pointer from integer without a cast
/usr/include/stdio.h:269: note: expected ‘const char * __restrict__’ but argument is of type ‘char’
第 11 行是带有 if 语句的行
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define FAIL -1
#define SUCCESS 1
int main (char *filename) {
FILE *fp;
char c;
int wordcount = 0;
if ((fp = fopen(*filename,"r")) == NULL)
return FAIL;
while (!feof(fp))
{
while(!isalpha(fgetc(fp)))
{
wordcount++;
}
}
printf("wordcount: %d",wordcount);
fclose(fp);
return SUCCESS;
}