delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/20/01:40:18

From: Adam Chlipala <chilip AT ptd DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: gets() and scanf("%s", &crap)
Date: 17 Jul 1997 23:55:46 GMT
Organization: ProLog - PenTeleData, Inc.
Lines: 29
Message-ID: <33CEB0DA.DC0DDD86@ptd.net>
References: <33CE3B9D DOT FA878F7A AT sunchem DOT chem DOT uga DOT edu>
Reply-To: chilip AT ptd DOT net
NNTP-Posting-Host: cs5-02.all.ptd.net
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Robert Herrick wrote:

> ... the gets(), scanf("%c", &character) and
> scanf("%s", &string) get missed.  ...

I don't know why the first two wouldn't work (unless you aren't pressing
enter after typing the string for the first one or the character for the
second), but the second form should not work in either UNIX or DOS.  You
don't put an & before a string passed to scanf().  This is because, as a
string is a char array, the value of the string arrary name itself
contains the location of the string array because it is actually a
pointer.  Putting an & before the array name returns a pointer to the
location of a pointer to the string.  To scanf() a string, you would use
scanf("%s", string);

>
>
> Thanks,
> Robert Herrick



-- Adam Chlipala
   chilip AT ptd DOT net
   ICQ UIN: 489166
   Aanigo Software Productions
   http://www.dragonfire.net/~psi/aanigo/


- Raw text -


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