how does fgets internally works?

Posted by Registered User on Stack Overflow See other posts from Stack Overflow or by Registered User
Published on 2011-06-22T07:26:17Z Indexed on 2011/06/22 8:22 UTC
Read the original article Hit count: 288

Filed under:
|
|
|

Well it is a basic question but I seem confused enough.

#include<stdio.h>
int main()
{
char a[100];
printf("Enter a string\n");
scanf("%s",a);
}

Basically the above is what I want to achieve. If I enter a string

James Bond

then I want that to be stored in array a. But the problem is because of presence of a blank space in between only James word is stored. So how can I solve this one.

UPDATE
After the replies given below I understand fgets() would be a better choice. I want to know internal working of fgets as why is it able to store the string with space where as scanf is not able to do the same.

© Stack Overflow or respective owner

Related posts about c

    Related posts about string