Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!yoyo.aarnet.edu.au!sirius.ucs.adelaide.edu.au!adam.adelaide.edu.au!phil From: phil@adam.adelaide.edu.au (Phil Kernick) Newsgroups: comp.sys.amiga.programmer Subject: Re: SAS-C problem (bug) with fscanf Message-ID: Date: 25 Mar 91 01:50:37 GMT References: Sender: news@ucs.adelaide.edu.au Distribution: comp Organization: University of Adelaide, South Australia Lines: 57 Nntp-Posting-Host: adam.adelaide.edu.au fiffi@opal.cs.tu-berlin.de (Carsten Hoehne) writes: >fscanf has the following template >fsanf(File *file,char *format-string,...) [stuff deleted] >3. fscanf(file,"\n%c",&c) must skip white spaces and then read a non blank > character in the Variable c This is not how scanf works with characters. From the unix man pages... The control string usually contains conversion specifica- tions, which are used to direct interpretation of input sequences. The control string may contain: 1. White-space characters (SPACE, TAB, or NEWLINE) which, except in two cases described below, cause input to be read up to the next non-white-space character. The conversion character indicates the interpretation of the input field; the corresponding pointer argument must usually be of a restricted type. For a suppressed field, no pointer argument is given. The following conversion characters are legal: c A character is expected; the corresponding argu- ment should be a character pointer. The normal skip over white space is suppressed in this case; to read the next non-space character, use %1s. If a field width is given, the corresponding argument should refer to a character array, and the indi- cated number of characters is read. Notice that the "skip-whitespace" is not done with character arguments. As the man page says, you must use %1s to get a single character after the next whitespace, but remember, scanf with return a null terminated string, so you will have to declare an array of char of length 2. The first to get your character and the second to take the \0. Example: char c[2]; fscanf(file, "%1s", c); will do what you want. Phil. -- o| /// Phil Kernick EMail: phil@adam.adelaide.edu.au |o | /// Departmental Engineer Phone: +618 228 5914 | o| \\\/// Dept. of Psychology Fax: +618 224 0464 |o | \/// University of Adelaide Mail: GPO Box 498 Adelaide SA 5001 |