Back to index

radiance  4R0+20100331
Functions | Variables
fgetword.c File Reference
#include "copyright.h"
#include "rtio.h"
#include <ctype.h>

Go to the source code of this file.

Functions

char * fgetword (char *s, int n, register FILE *fp)

Variables

static const char RCSid [] = "$Id: fgetword.c,v 2.6 2005/10/12 03:37:54 greg Exp $"

Function Documentation

char* fgetword ( char *  s,
int  n,
register FILE *  fp 
)

Definition at line 18 of file fgetword.c.

{
       int  quote = '\0';
       register char  *cp;
       register int  c;
                                   /* sanity checks */
       if ((s == NULL) | (n <= 0))
              return(NULL);
                                   /* skip initial white space */
       do
              c = getc(fp);
       while (isspace(c));
                                   /* check for quote */
       if ((c == '"') | (c == '\'')) {
              quote = c;
              c = getc(fp);
       }
                                   /* check for end of file */
       if (c == EOF)
              return(NULL);
                                   /* get actual word */
       cp = s;
       do {
              if (--n <= 0)        /* check length limit */
                     break;
              *cp++ = c;
              c = getc(fp);
       } while (c != EOF && !(quote ? c==quote : isspace(c)));
       *cp = '\0';
       if ((c != EOF) & (!quote))  /* replace space */
              ungetc(c, fp);
       return(s);
}

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: fgetword.c,v 2.6 2005/10/12 03:37:54 greg Exp $" [static]

Definition at line 2 of file fgetword.c.