Linux上C语言中的编译错误
我正在用Linux编写一个简单的程序,在编译时,我不断地遇到这个错误,不明白为什么——我把所有的Linux上C语言中的编译错误,c,linux,compiler-errors,C,Linux,Compiler Errors,我正在用Linux编写一个简单的程序,在编译时,我不断地遇到这个错误,不明白为什么——我把所有的或{}到位: if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */ { printf(" Error occurred attempting to stat fil
代码>或{}
到位:
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
ex1.c:49.1:错误:输入结束时需要声明或语句
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
我的代码:
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>
#include<fcntl.h>
int main (int argc, char* argv[])
{
if (argc!=3)
printf("Number of arugements passed is wrong - not 2\n");
char * file1 = argv[1];
char * file2 = argv[2];
int fdout1 = open(file1, O_RDONLY);
int fdout2 = open(file2, O_RDONLY);
struct stat stat_p1,stat_p2;
char * f1;
char * f2;
int i=0;
if (fdout1 < 0 || fdout2<0) /* means file open did not take place */
{
perror("ERROR opening files"); /* text explaining why */
return 1;
}
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
{
if((read(fdout1,f1,stat_p1.st_size)==-1) ||(read(fdout1,f1,stat_p1.st_size)==-1))
{
printf("ERROR reading files"); /* text explaining why */
return 1;
}
if (stat_p1.st_size!=stat_p2.st_size)
return 1;
if (strcmp(f1,f2)!=0)
return 1;
return 0;
}
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
#包括
#包括
#包括
#包括
#包括
int main(int argc,char*argv[])
{
如果(argc!=3)
printf(“通过的索赔数量错误-不是2\n”);
char*file1=argv[1];
char*file2=argv[2];
int fdout1=打开(仅限文件1);
int fdout2=打开(仅限文件2);
结构stat_p1、stat_p2;
char*f1;
char*f2;
int i=0;
如果(fdout1<0 | | fdout2似乎有打字错误
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
{
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
最后一个支撑应为闭合支撑
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
考虑到如果argc小于3,则必须退出程序
if (argc!=3)
printf("Number of arugements passed is wrong - not 2\n");
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
否则,这些声明无效
char * file1 = argv[1];
char * file2 = argv[2];
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
应该是这样的
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
右大括号是问题所在,这里是在程序上打开大括号。当缺少右大括号时,会发生此错误。如图所示:
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
{
你似乎有打字错误,你应该用右括号而不是左括号。我的手机屏幕上无法数到49。在源代码中标记有问题的一行,如下所示:/*第49行是代码的结尾。好吧,你的情况是手机,我的情况是网速慢。:)不管怎么说,他的问题已经解决了,这才是最重要的。你应该使用缩进;它会发现错误并重新格式化你的代码!问题是一个“{where should a}”,在第35行。顺便说一句:这花了大约30秒的时间才找到。我把你的代码放在geany编辑器中一个名为ex1.c的文件中。首先我注意到第40行是文件末尾的右大括号。然后我在文件中向后滚动。倒大括号很明显。你在使用什么linux编辑器?谢谢!我真的没有注意到信息技术
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}
if ( (stat (file1, &stat_p1) == -1) ||( stat (file2, &stat_p2) == -1) ) /* declare the 'stat' structure */
{
printf(" Error occurred attempting to stat files");
return 1;
}