www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/09/15:01:00

Message-ID: <34DF6028.348D@quantum.de>
Date: Mon, 09 Feb 1998 20:59:36 +0100
From: Tom Chojnacki <chojnack AT quantum DOT de>
Reply-To: chojnack AT quantum DOT de
Organization: Quantum Software GmbH, Dortmund, Germany
MIME-Version: 1.0
To: JODE <joakim AT hiway DOT fi>
CC: djgpp AT delorie DOT com
Subject: Re: Doing wrong! But where?
References: <34df149c DOT 11485161 AT news DOT hiway DOT fi>

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019