Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 错误:";预期的‘;)’;在字符串常量“之前”;_C_Gcc - Fatal编程技术网

C 错误:";预期的‘;)’;在字符串常量“之前”;

C 错误:";预期的‘;)’;在字符串常量“之前”;,c,gcc,C,Gcc,我正试图在Ubuntu中运行一个C程序(使用gcc编译器),出于某种原因,它不允许我使用strcpy函数。在下面代码的第二行: char test[10]; strcpy(test, "Hello!"); char c[2] = "A"; strcpy(test, c); 我得到以下错误: testChTh.c:56:14: error: expected ‘)’ before string constant strcpy(test, "Hello!"); ^

我正试图在Ubuntu中运行一个C程序(使用gcc编译器),出于某种原因,它不允许我使用strcpy函数。在下面代码的第二行:

char test[10];
strcpy(test, "Hello!");

char c[2] = "A";
strcpy(test, c);
我得到以下错误:

testChTh.c:56:14: error: expected ‘)’ before string constant
 strcpy(test, "Hello!");
              ^
testChTh.c:59:1: warning: data definition has no type or storage class
 strcpy(test, c);
 ^
testChTh.c:59:1: warning: type defaults to ‘int’ in declaration of ‘strcpy’ [-Wimplicit-int]
testChTh.c:59:1: warning: parameter names (without types) in function declaration
testChTh.c:59:1: error: conflicting types for ‘strcpy’
In file included from testChTh.c:3:0:
/usr/include/string.h:125:14: note: previous declaration of ‘strcpy’ was here
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
我包含了以下标题:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
在使用strcpy之前立即使用,无效

我检查了所有的左括号,它们都有相应的右括号)。另外,当我注释掉strcpy行时,错误消失了

任何洞察都是值得赞赏的

char test[10];
strcpy(test, "Hello!");

char c[2] = "A";
strcpy(test, c);
如果我理解正确,那么这些行在文件范围内。行
strcpy(测试“Hello!”)
是一条语句,并且语句仅在函数体中是合法的。因为编译器当时不需要语句,所以它试图将该行解释为声明

根据您的代码,以下内容是合法的(尽管它没有任何用处):

#包括
内部主(空){
煤焦试验[10];
strcpy(测试“你好!”);
字符c[2]=“A”;
strcpy(试验,c);
}
如果我理解正确,那么这些行在文件范围内。行
strcpy(测试“Hello!”)
是一条语句,并且语句仅在函数体中是合法的。因为编译器当时不需要语句,所以它试图将该行解释为声明

根据您的代码,以下内容是合法的(尽管它没有任何用处):

#包括
内部主(空){
煤焦试验[10];
strcpy(测试“你好!”);
字符c[2]=“A”;
strcpy(试验,c);
}

您确定双引号匹配吗?如果没有,请向我们展示产生错误的最小代码以及您是如何编译的。请提供重现问题的代码。如果没有代码,我们只能推测您似乎试图将错误消息作为图像包含,但失败了。不要那样做;将错误消息复制并粘贴为文本。您确定双引号匹配吗?如果没有,请向我们展示产生错误的最小代码以及您是如何编译的。请提供重现问题的代码。如果没有代码,我们只能推测您似乎试图将错误消息作为图像包含,但失败了。不要那样做;复制并粘贴错误消息为文本。哦,很好的捕获。。。毕竟这是一个MCVE…,但他在哪里包含头文件?@DavidC.Rankin查看错误消息中的行号。代码是实际源文件的一小部分,但它足以重现问题。您是100%正确的,问题已解决。非常感谢你!啊,明白了,你的接球是有道理的,我只是没有记下线号…哦,接球不错。。。毕竟这是一个MCVE…,但他在哪里包含头文件?@DavidC.Rankin查看错误消息中的行号。代码是实际源文件的一小部分,但它足以重现问题。您是100%正确的,问题已解决。非常感谢你!啊,明白了,你的捕获是有道理的,我只是没有在线路号码上找到。。。
char test[10];
strcpy(test, "Hello!");

char c[2] = "A";
strcpy(test, c);
#include <string.h>
int main(void) {
    char test[10];
    strcpy(test, "Hello!");

    char c[2] = "A";
    strcpy(test, c);
}