-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.3-Dynamic-Array-Structure.c
More file actions
54 lines (43 loc) · 1.19 KB
/
Copy path7.3-Dynamic-Array-Structure.c
File metadata and controls
54 lines (43 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
struct Student
{
char name[50];
int age;
int grNo;
};
void main()
{
int numStudents;
printf("Enter the number of students: ");
scanf("%d", &numStudents);
struct Student *students = (struct Student *)malloc(numStudents * sizeof(struct Student));
if (students != NULL)
{
for (int i = 0; i < numStudents; ++i)
{
printf("Enter details for student %d:\n", i + 1);
printf("Name: ");
scanf("%s", students[i].name);
fflush(stdin);
printf("Age: ");
scanf("%d", &students[i].age);
printf("Gr No: ");
scanf("%d", &students[i].grNo);
}
printf("\nDetails of the students:\n");
for (int i = 0; i < numStudents; ++i)
{
printf("Student %d:\n", i + 1);
printf("Name: %s\n", students[i].name);
printf("Age: %d\n", students[i].age);
printf("Grade: %d\n", students[i].grNo);
printf("\n");
}
}
else
{
printf("Memory allocation failed.\n");
}
free(students);
}