| |

VerySource

 Forgot password?
 Register
Search
Author: wangwendong

Structure problem

[Copy link]

0

Threads

25

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-2-6 10:45:01
| Show all posts
Problems with arrays and pointers.
Reply

Use magic Report

0

Threads

6

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-13 18:45:02
| Show all posts
it is good
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-29 10:00:01
| Show all posts
scanf don't\n
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-19 20:00:02
| Show all posts
#include <stdio.h>

struct person
{
char name[20];
char sex[3];
int age;
};

struct student
{
char number[10];
int score;
    struct person roommate;
};
void main()
{
int i;
    struct student myroommate[2];
printf("----------------&frac14;&AElig;&iquest;&AElig;&Iuml;&micro;&Egrave;&yacute;°à------------- --------\n");
printf ( "&Ccedil;&euml;&Ecirc;&auml;&Egrave;&euml;&Auml;&atilde;&Euml;&THORN;&Eacute; á&sup3;&Eacute;&Ocirc; ±&micro;&Auml;&Ntilde; §&ordm;&Aring;&iexcl;&cent;&sup3;&Eacute ;&frac14;¨&iexcl;&cent;&ETH;&Otilde;&Atilde;&ucirc;&iexcl;&cent;&ETH;&Ocirc;±&eth;&iexcl;&centute;&Aumac;&Aumac;&centute:1uo0Aumac;
printf("-----------×&cent;&Ograve;&acirc;&Ecirc;&auml;&Egrave;&euml;&cedil;÷&cedil;&ouml;&sup2;&iquest;·&Ouml;&circle',&·&Ouml;&iquest;&ordf;-----------\n");
for(i=0;i<2;i++)
{
printf("&Ntilde;§&ordm;&Aring;:");
scanf("%s",myroommate[i].number);
printf("&sup3;&Eacute;&frac14;¨:");
scanf("%d",&myroommate[i].score);
printf("&ETH;&Otilde;&Atilde;&ucirc;:");
scanf("%s",myroommate[i].roommate.name);
fflush(stdin);
printf("&ETH;&Ocirc;±&eth;:");
scanf("%s",myroommate[i].roommate.sex);
fflush(stdin);
printf("&Auml;ê&Aacute;&auml;:");
scanf("%d",&myroommate[i].roommate.age);
}
printf ( "&Euml;&THORN;&Eacute; á&sup3;&Eacute;&Ocirc; ±&micro;&Auml;&Ntilde; §&ordm;&Aring;&iexcl;&cent;&sup3;&Eacute;&frac14; ¨&iexcl;&cent;&ETH;&Otilde;&Atilde;&ucirc;&iexcl;&cent;&ETH;&Ocirc;±&eth;&iexcl;&cent;&Auml;ê&Aacute;&auml;·&Ouml;±&eth;&Ecirc;&Ccedil;:\n");
for(i=0;i<2;i++)
{
printf("&Ntilde;§&ordm;&Aring;:%s,&sup3;&Eacute;&frac14;¨:%d,&ETH;&Otilde;&Atilde;&ucirc;:%s,&ETH;0,&;%s,&ETH;0,&;ups;±0&Eacute;&frac14;¨:%d\n",
myroommate[i].number,
myroommate[i].score,
myroommate[i].roommate.name,
myroommate[i].roommate.sex,
myroommate[i].roommate.age);
}
}
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-19 20:30:01
| Show all posts
How could it be garbled?
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-19 20:45:01
| Show all posts
#include <stdio.h>

struct person
{
char name[20];
char sex[3];
int age;
};

struct student
{
char number[10];
int score;
    struct person roommate;
};
void main()
{
int i;
    struct student myroommate[2];
printf("----------------The third class of the Department of Accounting---------------------\n");
printf("Please enter the student ID, grade, name, gender, age of your dormitory member:\n");
printf("-----------Note that each part of the input is separated by','-----------\n");
for(i=0;i<2;i++)
{
printf("student number:");
scanf("%s",myroommate[i].number);
printf("score:");
scanf("%d",&myroommate[i].score);
printf("Name:");
scanf("%s",myroommate[i].roommate.name);
fflush(stdin);
printf("Gender:");
scanf("%s",myroommate[i].roommate.sex);
fflush(stdin);
printf("age:");
scanf("%d",&myroommate[i].roommate.age);
}
printf("The student ID, grade, name, gender, and age of the dormitory members are:\n");
for(i=0;i<2;i++)
{
printf("student ID:%s, grade:%d, name:%s, gender:%s, grade:%d\n",
myroommate[i].number,
myroommate[i].score,
myroommate[i].roommate.name,
myroommate[i].roommate.sex,
myroommate[i].roommate.age);
}
}
How about this time? The main reason is that LZ did not clear STDIN\n. There is no problem on my machine, but there is no fault-tolerant processing for input! ! ! !
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list