I am working on a simple C program using a struct named 'student'. Here is my code
#include<stdio.h>
#include<stdlib.h>
struct student {
char name[50];
int id;
float marks_1;
float marks_2;
};
void main(){
int num,a,i;
printf("Enter number of students\n");
scanf("%d",&num);
struct student s[num];
for(i=0;i<num;i++)
{
a=i+1;
printf("Enter name of student number %d\n",a);
scanf("%[^\n]%*c",s[i].name);
}
}
When I run the program I am able to enter the number of students correctly, but after that I am not able to enter the name corresponding to each student. This is the output that I get.
Enter number of students
2
Enter name of student number 1
Enter name of student number 2
RUN FINISHED; exit value 2; real time: 1s; user: 0ms; system: 0ms
What might be the problem? Any help appreciated