C language learned by suffering
C language learned by suffering
Exercise 16
fundamental knowledge
Q1-1
What do you call the method of putting together several different types?
program writing
Q2-1
Create a program to input and display the names, ages, and genders of three people.
The data should be stored in a structure.
Also, create dedicated functions for data input and display, respectively.
The data should be stored in a structure.
Also, create dedicated functions for data input and display, respectively.
descriptive expression
Q3-1
You can declare variables separately and store data without any problems, but you can't declare them separately.
Briefly explain why we bother to use structures.
Briefly explain why we bother to use structures.
Basic Knowledge (sample answers)
Solution 1-1
structure
Program writing (example of solution)
Solution 2-1
#include <stdio.h>
#include <string.h>
typedef struct
{
char name[256];
int age;
int sex;
} People;
void InputPeople(People *data);
void ShowPeople(People data);
int main(void)
{
People data[3];
People data[3]; int i;
for (i = 0; i < 3; i++)
{
InputPeople(&data[i]);
}
for (i = 0; i < 3; i++)
{
ShowPeople(data[i]);
}
return 0;
}
void InputPeople(People *data)
{
printf("Name:");
scanf("%s", data->name);
printf("Age:");
scanf("%d", &data->age);
printf("Gender (1-male, 2-female):"); scanf("%d", &data->age); printf("%d", &data->age); scanf("%d", &data->age)
scanf("%d", &data->sex);
printf("\n");
}
void ShowPeople(People data)
{
char sex[16];
printf("Name:%s\n", data.name);
printf("Age:%d\n", data.age);
if (data.sex == 1)
{
strcpy(sex, "male");
}
else
{
strcpy(sex, "female");
}
printf("Sex:%s\n", sex);
printf("\n");
}
*If we greatly expand this program, we can use the
It is also possible to create an address book management program with sufficient utility.
Short Answer Type (Sample Answer)
Solution 3-1
It is convenient to manage related data together if it is made into a structure.
About this Site
The C language (bitter C), which is learned by suffering, is
This is the definitive C language introductory site.
It systematically explains the basic functions of the C language and
It is as complete as or better than any book on the market.