typedef struct addressbook
{
char name[12];
int tel[12];
int email[12];
char home[12];
}mess;
#include<stdio.h>
void showAll(mess *p,int n)
{ printf("%s\t%s\t%s\t%s\n","name","tel","email","home");
int i;
for(i=0;i<n;i++)
{
printf("%s\t%d\t%d\t%s\n",*(p+i)->name,*(p+i)->tel,*(p+i)->email,*(p+i)->home);
}
}
```c
[Error] format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Werror=format=]
[Error] format '%s' expects argument of type 'char *', but argument 5 has type 'int' [-Werror=format=]

C语言通讯录printf问题,为什么name和home是int型变量?
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
4条回答 默认 最新
- qzjhjxj 2023-02-16 20:59关注
修改如下,改动处见注释,供参考:
#include<stdio.h> #include<string.h> typedef struct addressbook { char name[12]; int tel; //[12];修改 int email; //[12];修改 char home[12]; }mess; void showAll(mess *p,int n) { printf("%s\t%s\t%s\t%s\n","name","tel","email","home"); int i; for(i=0;i<n;i++) { printf("%s\t%d\t%d\t%s\n",(p+i)->name,(p+i)->tel,(p+i)->email,(p+i)->home); //修改 //printf("%s\t%d\t%d\t%s\n",*(p+i)->name,*(p+i)->tel,*(p+i)->email,*(p+i)->home); } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用