#include <stdio.h>
#include <string.h>
char* str[3];
str[0] ="hello";
str[1] ="do";
str[2] ="learn";
int main(void)
{
int flag = 3;
// char* str[3];
// str[0] ="hello";
// str[1] ="do";
// str[2] ="learn";
while(flag > 0)
{ flag--;
// print(flag);
printf("%s\n",str[flag]);
}
}
错误是
test.c:5:2: 警告: 数据定义时没有类型或存储类 [默认启用]
test.c:5:2: 错误: 与‘str’类型冲突
test.c:4:9: 附注: ‘str’的上一个声明在此
test.c:5:2: 错误: 用窄字符串初始化宽字符数组
test.c:6:2: 警告: 数据定义时没有类型或存储类 [默认启用]
test.c:6:2: 错误: 与‘str’类型冲突
test.c:4:9: 附注: ‘str’的上一个声明在此
test.c:6:2: 错误: 用窄字符串初始化宽字符数组
test.c:7:2: 警告: 数据定义时没有类型或存储类 [默认启用]
test.c:7:2: 错误: 与‘str’类型冲突
test.c:4:9: 附注: ‘str’的上一个声明在此
test.c:7:2: 错误: 用窄字符串初始化宽字符数组
test.c: 在函数‘main’中:
test.c:20:3: 警告: 格式 ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat]
---
我把str[0] ="hello";
str[1] ="do";
str[2] ="learn";
放到main里面就可以正常编译了。以前没注意到。谢谢大家~