打开文件的问题
#include<stdio.h>#include<stdlib.h>//提供exit()模型
int main(int argc, char argv[] )
{
int ch;
FILE *fp;
unsigned long count = 0;
if(argc != 2)
{
printf("Usage : %s filename\n",argv);
exit(EXIT_FAILURE);
}
if((fp = fopen(argv, "r")) == NULL);
{
printf("Can't open %s \n",argv);
exit(EXIT_FAILURE);
}
while((ch = getc(fp)) != EOF)
{
putc(ch, stdout);
count++;
}
fclose(fp);
printf("FIle %s has %lu characters\n",argv, count);
return 0;
}
程序感觉没问题,但是报这个错误是怎末回事呢?该怎么解决呢
c:\xsl\c6.0.zuoye\200521\count.c(15) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'char '
c:\xsl\c6.0.zuoye\200521\count.c(15) : warning C4024: 'fopen' : different types for formal and actual parameter 1 度娘是个很好用的东西:
https://zhidao.baidu.com/question/495723873227576884.html
https://zhidao.baidu.com/question/570191903.html
Twilight6 发表于 2020-5-22 13:46
度娘是个很好用的东西:
https://zhidao.baidu.com/question/495723873227576884.html
不一样啊,他那个是定义错误,但我这里定义没错的,而且fopen也报错了 a1764441928 发表于 2020-5-22 16:03
不一样啊,他那个是定义错误,但我这里定义没错的,而且fopen也报错了
认真检查下吧,我也不清楚了 抱歉哈 Twilight6 发表于 2020-5-22 13:46
度娘是个很好用的东西:
https://zhidao.baidu.com/question/495723873227576884.html
是编译器的问题吗 ? a1764441928 发表于 2020-5-22 16:04
是编译器的问题吗 ?
嗯 也有可能吧 怎么能如此的不认真?
#include<stdio.h>
#include<stdlib.h>//提供exit()模型
//int main(int argc, char argv[] )
int main(int argc, char *argv[] )
{
int ch;
FILE *fp;
unsigned long count = 0;
if(argc != 2)
{
printf("Usage : %s filename\n",argv);
exit(EXIT_FAILURE);
}
//if((fp = fopen(argv, "r")) == NULL);
if((fp = fopen(argv, "r")) == NULL)
{
printf("Can't open %s \n",argv);
exit(EXIT_FAILURE);
}
while((ch = getc(fp)) != EOF)
{
putc(ch, stdout);
count++;
}
fclose(fp);
printf("FIle %s has %lu characters\n",argv, count);
return 0;
}
人造人 发表于 2020-5-22 22:47
怎么能如此的不认真?
太低级的错误反而看不见{:10_266:}谢谢 a1764441928 发表于 2020-5-23 15:15
太低级的错误反而看不见谢谢
太低级的错误让编译器来帮你检查,^_^
gcc -Wall -o main main.c
页:
[1]