Mail Archives: djgpp/1998/02/09/15:01:00
JODE wrote:
>
> **************************************************
>
> struct Man {
>
> char stick[1];
>
> }man1;
>
> fgets(man1.stick, 1, thefile1);
>
> printf("%C\n", man1.stick);
>
> *****************************************************
>
> The thefile1 first line contains only a single "Y" charracter!
> I just can't get it right! The printf prints something realy wierd!
> Where do I do wrong?
printf("%C\n", man1.stick);
^^ <- here is your problem
You should use '%s' format specification type to print the string.
Or, if you want to print just first character of it use something like
that:
printf("%c\n", (man1.stick)[0]);
'stick' member of 'man1' structure is array of characters.
Its length is one but it is array!
You made confused printf function because it 'thought' that it received
an character (%c) and actually it received an array.
Hope that helps!
Tom
- Raw text -