Dynamic mem and struct

Run Settings
LanguageC
Language Version
Run Command
#include <stdio.h> #include <stdlib.h> struct course { char sub[20]; int marks; }; int main(){ struct course *ptr; int i , noOfRecords; printf("enter the no of records:"); scanf("%d",&noOfRecords); ptr = (struct course*)malloc(sizeof(struct course)*noOfRecords); for(i = 0;i<noOfRecords;i++){ scanf("%s %d",ptr[i].sub,&ptr[i].marks); } for(i = 0;i<noOfRecords;i++){ printf("%s\t %d\n",ptr[i].sub,ptr[i].marks); } }
Editor Settings
Theme
Key bindings
Full width
Lines