I am new to C language and working on a small program.
Actually I am trying to take string from the user using scanf. But whenever I enter string with space, program keeps on running infinite and I had to press stop button. I have seen examples online and I have used them as well but that give me a new error then.
Here is my code
struct student s1;
char input[MAX_NAME_SIZE];
printf("Enter name>");
scanf("%s",input);
if(strlen(input) > 10)
{
int l;
for(l = 0 ;l < 10;l++)
s1.name[l] = input[l];
}
int error = 0;
do
{
if(error == 1)
printf("Invalid day. ");
printf("Enter birthday: day>");
scanf("%u",&s1.birthday.day);
error = 1;
}while(s1.birthday.day < 1 || s1.birthday.day > 31); //checking the criteria
I also have used scanf("%[^\n]s,input) but it then skip the scanf and go to the second scanf.
Please help