2.c: In function ‘main’: 2.c:32:3: warning: implicit declaration of function ‘strcpy’ [-Wimplicit-function-declaration] strcpy(a[i].name,name_a); ^~~~~~ 2.c:32:3: warning: incompatible implicit declaration of built-in function ‘strcpy’ 2.c:32:3: note: include ‘<string.h>’ or provide a declaration of ‘strcpy’ 2.c:33:10: warning: passing argument 1 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion] strcpy(a[i].age,age_a); ^ 2.c:33:10: note: expected ‘char *’ but argument is of type ‘int’ 2.c:33:19: warning: passing argument 2 of ‘strcpy’ from incompatible pointer type [-Wincompatible-pointer-types] strcpy(a[i].age,age_a); ^~~~~ 2.c:33:19: note: expected ‘const char *’ but argument is of type ‘int *’ 2.c:34:10: warning: passing argument 1 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion] strcpy(a[i].id,id_a); ^ 2.c:34:10: note: expected ‘char *’ but argument is of type ‘int’ 2.c:34:18: warning: passing argument 2 of ‘strcpy’ from incompatible pointer type [-Wincompatible-pointer-types] strcpy(a[i].id,id_a); ^~~~
时间: 2024-03-27 10:35:02 浏览: 142
iyon-module-implicit.rar_https://www.iyon
这个警告信息是因为代码中使用了`strcpy()`函数,但是没有包含`<string.h>`头文件,所以编译器无法识别该函数的声明。同时,还存在一些参数不匹配的问题,例如传递给`strcpy()`函数的参数类型与函数原型不匹配等。
要解决这个问题,可以在代码中包含`<string.h>`头文件,这样编译器就可以识别`strcpy()`函数的声明。另外,需要注意传递给`strcpy()`函数的参数类型是否正确,例如第33行和第34行传递的参数类型应该是`char *`,而不是`int`类型。
修复代码如下所示:
```c
#include <stdio.h>
#include <string.h>
struct student{
char name[20];
char age[10];
char id[20];
};
int main(){
struct student a[100];
int i=0, n=0;
char name_a[20], age_a[10], id_a[20];
printf("Please input n: ");
scanf("%d", &n);
for(i=0;i<n;i++){
printf("Please input name, age, id: ");
scanf("%s %s %s", name_a, age_a, id_a);
strcpy(a[i].name,name_a);
strcpy(a[i].age,age_a);
strcpy(a[i].id,id_a);
}
for(i=0;i<n;i++){
printf("%s %s %s\n",a[i].name,a[i].age,a[i].id);
}
return 0;
}
```
阅读全文