|
| 1 | +#include <stdio.h> |
| 2 | +#include <stdlib.h> |
| 3 | +struct course { |
| 4 | + int marks; |
| 5 | + char subject[30]; |
| 6 | +}; |
| 7 | + |
| 8 | +int main() { |
| 9 | + struct course *ptr; |
| 10 | + int noOfRecords; |
| 11 | + printf("Enter the number of records: "); |
| 12 | + scanf("%d", &noOfRecords); |
| 13 | + |
| 14 | + // Memory allocation for noOfRecords structures |
| 15 | + ptr = (struct course *)malloc(noOfRecords * sizeof(struct course)); |
| 16 | + for (int i = 0; i < noOfRecords; ++i) { |
| 17 | + printf("Enter subject and marks:\n"); |
| 18 | + scanf("%s %d", (ptr + i)->subject, &(ptr + i)->marks); |
| 19 | + } |
| 20 | + |
| 21 | + printf("Displaying Information:\n"); |
| 22 | + for (int i = 0; i < noOfRecords; ++i) { |
| 23 | + printf("%s\t%d\n", (ptr + i)->subject, (ptr + i)->marks); |
| 24 | + } |
| 25 | + |
| 26 | + free(ptr); |
| 27 | + |
| 28 | + return 0; |
| 29 | +} |
0 commit comments