gpt4 book ai didi

c - 我应该如何打印指针指向的值?

转载 作者:行者123 更新时间:2023-11-30 21:48:25 24 4
gpt4 key购买 nike

我试图向用户显示一系列问题,然后扫描响应。我的代码构建时没有错误,但是当我运行它时,出现错误:期望指向 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);

}

最佳答案

尝试这个(&全部删除)请参阅我上面的评论以了解原因。

#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);

}

关于c - 我应该如何打印指针指向的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19276390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com