On Sat, Jun 7, 2008 at 5:38 PM, Bill Cunningham <[EMAIL PROTECTED]> wrote:
>> It's not at all clear what you're trying to do here. Your e-mail has
>> no context, and your code is insufficient commented.
>>
>> You are not using the 'buf' array, and you are treating the 'input'
>> variable as a string when it is a single char. fgets expects a char
>> array as the first parameter, so consequently your code will not
>> compile.
>
> Parameter 2 of fgets is an int. Parameter 1 takes a pointer to char. One
> could try this.
>
> int main(void) {
> int buf[10];
> char input; /* for parameter 1 */
> fgets( input, sizeof(buf), stdin );
> printf( "%s\n", input );
> }
No. input is not a pointer. You should be using a static char array or
dynamically allocate memory for char *. Why are you declaring buf and
then never doing anything with it? How would you expect to put 10
characters into a single char? Also, fgets terminates the string with
'\0' when it reaches either the size or \n, and if you are trying to
collect 10 characters, then you will not have space for the
terminating '\0'.
> This should, and this is untested, print a string from input.
I'd be surprised if this even compiled, since the first parameter to
fgets is not char *
-- Brett
------------------------------------------------------------
"In the rhythm of music a secret is hidden;
If I were to divulge it, it would overturn the world."
-- Jelaleddin Rumi