Mail Archives: djgpp/1998/02/11/12:46:14
JODE wrote:
> struct Man {
>
> char stick[1];
>
> }man1;
>
> fgets(man1.stick, 1, thefile1);
>
> printf("%C\n", man1.stick);
There are two problems here. First, fgets always keeps the buffer
NUL-terminated, so fgets will never read any data. Perhaps you meant to
use read, if you don't want the data to be NUL-terminated (which it
can't be since there's only room for the NUL itself and no other data).
Second, in the context of this program (note it still won't work because
of the above problem), you're passing the address of man1.stick to
printf and trying to print it as a character (which is the %c format
specifier, not %C). You meant:
printf("%c\n", man1.stick[0]);
Again, though, because of the above problem, changing this won't help.
--
Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com
Alcyone Systems / http://www.alcyone.com/max/
San Jose, California, United States / icbm://+37.20.07/-121.53.38
\
"Life may be / the product of imperfections."
/ (Marclo Gleiser)
- Raw text -