【发布时间】:2013-03-30 02:15:59
【问题描述】:
我是C新手,我在网上找到了这个关于字符串和数组的教程,并尝试做这个程序。他们正在使用 Eclipse,而我正在使用 Visual Studio 2010 ...请帮助和解释。 我遇到了这些问题:
error C2143: syntax error : missing ';' before 'type'
error C2143: syntax error : missing ';' before 'type'
error C2143: syntax error : missing ')' before 'type'
error C2143: syntax error : missing ';' before 'type'
error C2065: 'cp' : undeclared identifier
error C2100: illegal indirection
warning C4552: '!=' : operator has no effect; expected operator with side-effect
error C2059: syntax error : ')'
error C2065: 'cp' : undeclared identifier
error C2143: syntax error : missing ';' before '{'
error C2065: 'cp' : undeclared identifier
error C2100: illegal indirection
这是代码:
#include <stdio.h>
#include <conio.h>
int main(char argc, char**argv){
char s[] = "string";
printf("string is: %s\n", s);
for(char *cp = s; *cp !=0; ++cp) {
printf("char is %c\n", *cp);
}
getch();
}
【问题讨论】:
-
vs2012 对此很满意 :)
-
旁注:将
char argc更改为int argc。 -
@gongzhitaao 有什么编译器?
-
@Perception 它行不通
-
我认为您正在使用 C89 编译器运行。不允许像 for 循环这样的 inline-decls。
标签: c arrays string visual-studio-2010