Gregory Pietsch
5/4/2011 11:48:00 PM
On Apr 23, 8:46 pm, "Bill Cunningham" <nos...@nspam.invalid> wrote:
> I have been away from C for awhile and need a refresher. fgets 2nd
> parameter takes an int but the 1st takes a string. When I compile what I
> write everything works fine but this is what I type-
>
> #include <stdio.h>
>
> int main()
> {
> char p[5];
> printf("enter code-> ");
> fflush(stdout);
> fgets (p,sizeof(int),stdin);
What's the sizeof(int) for? The fgets function reads in a string. If
you want to convert the string to an integer, use atoi, atol, atoll,
strtol, strtoul, or strtoull. -- Gregory Pietsch
> printf("%s\n",p);
> return 0;
>
> }
>
> Everything's cool and works the way I want. But is there a similarity
> with the 5 chars and the ints in fgets 2nd parameter? I shouldn've used 5
> for int should I have?
>
> Bill