-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04.struct.c
50 lines (41 loc) · 950 Bytes
/
04.struct.c
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
//this program we will allocate memory dinamicaly
#include <stdio.h>
#include <stdlib.h>
//struct data allocationi
struct course
{
int mark;
char subject[30];
};
int main()
{
//variable declaration
struct coures *ptr;
int n, i;
//read input from user
printf("How many student record you are entered");
scanf("%d", &n);
//dynamic memory allocation
ptr = (struct course *)malloc(n * sizeof(struct course));
if (ptr == NULL)
{
printf("MEMORY_NOT_ALLOCATED_FOR_PTR");
exit(0);
}
//read stuent data from user
printf("enter student detail");
for (i = 0; i < n; ++i)
{
scanf("%s", (ptr + i)->subject);
scanf("%d", &(ptr + i)->mark);
}
// displaying message
for (i = 0; i < n; ++i)
{
printf("%s\n", (ptr + i)->subject);
printf("%d", &(ptr + i)->mark);
printf("\n");
}
//memory free up
free(ptr);
}