我试图向用户显示一系列问题,然后扫描回复。我的代码构建没有错误,但是当我运行它时我得到错误:期望指向char但指向聚合的指针。这里有什么错误?
#include <stdio.h>
int main ()
{
char name[50] , lastname[50] , add[100], post[50], town[60], state[60], tel[50];
printf ("**** PLEASE ENTER THIS CONFIDENTIAL INFORMATION****");
printf ("\n=================================================\n=================================================");
printf ("\n\nFirst name:");
scanf ("%s",&name);
printf ("\nLast name:");
scanf ("%s",&lastname);
printf ("\nAddress Please:");
scanf ("%s",&add);
printf ("\nPostcode:");
scanf("%s",&post);
printf ("\ntown:");
scanf ("%s",&town);
printf("\nTelephone number:");
scanf("%s",&tel);
printf ("\n\n****CONFIDENTIAL INFORMATION****");
printf ("\n=================================================\n=================================================");
printf ("\nName:%s %s \n" ,name ,lastname);
printf ("Address:%s\n",add);
printf ("postal code:%s\n",post);
printf ("Town:%s\n",town);
printf ("State:%s\n",state);
printf ("Tel:%s\n",tel);
}
答案 0 :(得分:0)
尝试此操作(&amp;全部删除)请参阅上面的评论。
#include <stdio.h>
int main ()
{
char name[50] , lastname[50] , add[100], post[50], town[60], state[60], tel[50];
printf ("**** PLEASE ENTER THIS CONFIDENTIAL INFORMATION****");
printf ("\n=================================================\n=================================================");
printf ("\n\nFirst name:");
scanf ("%s",name);
printf ("\nLast name:");
scanf ("%s",lastname);
printf ("\nAddress Please:");
scanf ("%s",add);
printf ("\nPostcode:");
scanf("%s",post);
printf ("\ntown:");
scanf ("%s",town);
printf("\nTelephone number:");
scanf("%s",tel);
printf ("\n\n****CONFIDENTIAL INFORMATION****");
printf ("\n=================================================\n=================================================");
printf ("\nName:%s %s \n" ,name ,lastname);
printf ("Address:%s\n",add);
printf ("postal code:%s\n",post);
printf ("Town:%s\n",town);
printf ("State:%s\n",state);
printf ("Tel:%s\n",tel);
}
答案 1 :(得分:0)
当你为字符串执行scanf时,你不需要
scanf("%s",&str);
而不是做
scanf("%s",str).
答案 2 :(得分:0)
#include <stdio.h>
int main()
{
int i=3;
int *j;
j = &i;
printf("i %d\n",i);//value of i
printf("j %d",*j);//value of i in j
printf("j %d",&j);// address of i in j
return 0;
}
因此,这就是完成引用和取消引用指针的方式。我只是提供了线索。现在,您可以动脑...干杯!