what's the problem in input(std[i].name)? i'm trying to take input string with whitespace but can't. Someone please help me.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
struct student
int roll;
char name[30];
int age;
} std[3];
for(int i=0;i<3;i++){
int j=i+1;
printf("\nStudent%d\n\tEnter Roll:",j);
scanf("%d",&std[i].roll);
//-----------***********-----------------------------------
printf("\n\tEnter name:");
scanf("%[^\n]",std[i].name);/* prblem */
//------------****************----------------------------------
printf("\n\tEnter age:");
scanf("%d",&std[i].age);
}
for(int i=0;i<3;i++){
int j=i+1;
printf("\n student%d\n\tRoll:%d",j,std[i].roll);
printf("\n\t name:%s",std[i].name);
printf("\n\t age:%d",std[i].age);
}
return 0;
}
output: Program output