On executing the code below, the output comes out to be
Enter activity selected: hello
After taking input for number of activities and entering the activities . The scanf()
is getting completely skipped.
I tried everything found on the internet like using getchar()
instead of scanf()
, putting a getchar()
before taking input and using fflush()
.
But nothing seems to be working. Can anyone tell what is the mistake I am making?
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
char name;
int start;
int finish;
}activity;
int main()
{
int n;
printf("Enter number of activities: ");
scanf("%d",&n);
activity* a = (activity*)malloc(sizeof(activity)*n);
printf("Enter activities: ");
for(int i=0;i<n;i++)
{
scanf("%c %d %d ",&(a[i].name),&(a[i].start),&(a[i].finish));
}
//getchar();
char ch;
int s,f;
printf("Enter activity selected:");
//fflush(stdin);
//scanf(" %c",&ch);
ch = getchar();
printf("hello");
return 0;
}