I am getting problem when using scanf()
to take int input, then move to take a whole string that also accept whitespace in it. But somehow the scanf()
take place first before the printf()
even showed up. Still playing around with either scanf()
and fgets()
for proper solutions
Here is my snippet code
int age; char name_user[35];
printf("age\t: "); scanf("%d\n",&age);
printf("name\t: "); scanf("%[^\n]%*s", name_user);
printf("result\t: %s is %d years old\n",name_user,age);
with the output like this
age : 30
hotpotcookie
name : loremipsum
result : hotpotcookie is 30 years old
are there any workarounds for the input hotpotcookie
take place in the name
output? so it could be similar like this
age : 30
name : hotpotcookie
result : hotpotcookie is 30 years old