current position:Home>C language, ask a question about structure

C language, ask a question about structure

2022-01-26 23:45:51 CSDN Q & A

devc++

#include<stdio.h>#define N 2struct tele{    char name;    int telenumber;    char email;};struct tele tel[N];int main(){    void print(struct tele tel[N]);    int i;    for(i=0;i<N;i++)    {        printf("\n Please enter the first %d A classmate's address book :\n",i+1);        printf(" full name :");scanf("%c",&tel[i].name);        printf(" Phone number :");scanf("%d",&tel[i].telenumber);        printf(" E-mail address :");scanf("%c",&tel[i].email);    }    printf("\n");    print(tel);}void print(struct tele tel[N]){    int i;    printf("\n full name   Phone number   E-mail address \n");    for(i=0;i<N;i++)    {        printf("%c %d %c",tel[i].name,tel[i].telenumber,tel[i].email);        printf("\n");    }}``` The topic is to establish a simple classmate address book , Input 10 A classmate's communication information ( Address book information includes name 、 Phone number 、 email ) And the output . For testing purposes , Reduce the number of people in the code , The code is as follows :#include<stdio.h>#define N 2struct tele{    char name;    int telenumber;    char email;};struct tele tel[N];int main(){    void print(struct tele tel[N]);    int i;    for(i=0;i<N;i++)    {        printf("\n Please enter the first %d A classmate's address book :\n",i+1);        printf(" full name :");scanf("%c",&tel[i].name);        printf(" Phone number :");scanf("%d",&tel[i].telenumber);        printf(" E-mail address :");scanf("%c",&tel[i].email);    }    printf("\n");    print(tel);}void print(struct tele tel[N]){    int i;    printf("\n full name   Phone number   E-mail address \n");    for(i=0;i<N;i++)    {        printf("%c %d %c",tel[i].name,tel[i].telenumber,tel[i].email);        printf("\n");    }}![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/682554456936172.png "#left") Enter into the email section ( It's a character ) Will automatically skip , I'm really puzzled , In addition , Why? scanf There is no... In the function &( Fetch address operator ) No way ? I see some in books that can be omitted , do not know why 



Refer to the answer 1:

Well, for the first time csdn, This code was submitted twice , Sorry, sorry.




Refer to the answer 2:



Refer to the answer 3:

img




Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262345488033.html

Random recommended