delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/03/15:00:49

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: example of sscanf function
Date: Sun, 02 Nov 1997 11:34:17 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 35
Message-ID: <345C6539.6BD7@cs.com>
References: <345B78DF DOT 53B722B1 AT netcom DOT ca>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp229.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

jb AT netcom DOT ca wrote:
> 
> could anyone please give me an example of how to use the sscanf
> function?

This is basic C you're asking about here, which is not the purpose of
this newsgroup (try comp.lang.c instead).  Any C textbook should tell
you how to use sscanf(), and so should the libc documentation that comes
with DJGPP.  Nevertheless, since you took the time to ask I'll go ahead
and answer...

sscanf() parses input from a string in the exact same manner that
scanf() parses input from stdin.  You read in a string somehow (via
gets() or whatever), and then tell sscanf() to read from the string. 
Otherwise, it's identical to scanf().

Example:

    char string[200];
    int i1, i2, i3;

    printf( "Please type three numbers:  " );
    gets( string );
    sscanf( string, "%d %d %d", &i1, &i2, &i3 );

If this still doesn't clear things up, please post your code that
doesn't work and we'll debug it for you.

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "Courage is the complement of fear.  |
|       aka Fighteer I       | A man who is fearless cannot be      |
|   mailto:fighteer AT cs DOT com   | courageous.  (He is also a fool.)"   |
| http://www.cs.com/fighteer |                    - Lazarus Long    |
---------------------------------------------------------------------

- Raw text -


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