-8

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

}
4

3 回答 3

0

当你对字符串进行 scanf 时,你不需要

scanf("%s",&str);

而是做

scanf("%s",str).

于 2013-10-09T16:48:01.537 回答
0

试试这个(&全部删除)查看我上面的评论的原因。

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

}
于 2013-10-09T16:16:52.873 回答
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;
}

因此,这就是引用和取消引用指针的方式。我只是给出了线索​​。现在你用你的大脑......干杯!

于 2019-08-13T09:24:33.557 回答