Following is the simple program of taking a name and marks from user.
#include <stdio.h>
int main()
{
char name[11];
int marks;
printf("write name of student:\n");
fgets(name, 11, stdin);
printf("write marks of %s student:", name);//problem
scanf("%d", &marks);
return 0;
}
In 2nd printf I have used %s to show the entered name by user and ask for marks of that name. Problem is that after showing the name(%s i.e entered by user) a new line character get printed on screen and the next word (i.e "student:") get printed in new line. I am unable to find the error of this. Following is the result on console.
write name of student:
Suraj
write marks of Suraj
student:50
[Program finished]
Suraj is the name and 50 is the marks written on console.