Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- gcc -std=c99 -Wall -o "input" "input.c"
- */
- #include <stdio.h>
- #include <stdlib.h>
- struct stud{
- char name[50];
- char fname[50];
- int balls;
- };
- typedef struct stud st;
- void readStudent(st* student){
- printf("Введите Имя:");
- scanf("%s", student->name);
- printf("Введите Фамилию:");
- scanf("%s", student->fname);
- printf("Введите баллы:");
- scanf("%d", &student->balls);
- }
- void readStudents(st** student, int count){
- for (int i = 0; i < count ; i++){
- student[i] = (st*) malloc (sizeof(st));
- readStudent(student[i]);
- }
- }
- void printStudents(st** student, int count){
- for (int i = 0; i < count ; i++){
- printf("Имя:");
- printf("%s\n", student[i]->name);
- printf("Фамилия:");
- printf("%s\n", student[i]->fname);
- printf("баллы:");
- printf("%d\n", student[i]->balls);
- }
- }
- int main(int argc, char **argv){
- int count = 3;
- printf("Введите кол-во:");
- scanf("%d", &count);
- st** mas = (st**)malloc(sizeof(st**)*count);
- readStudents(mas, count);
- printStudents(mas, count);
- for (int i = 0; i < count; i++)
- {
- free(mas[i]);
- }
- free(mas);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement