Compartilhar via


fgets, fgetws (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Get a string from a stream.

char *fgets(    char*string,intn,FILE*stream);wchar_t *fgetws(    wchar_t*string,intn,FILE*stream);

Parameters

  • string
    Storage location for data.
  • n
    Maximum number of characters to read.
  • stream
    Pointer to FILE structure.

Return Values

Each of these functions returns string.

NULL is returned to indicate an error or an end-of-file condition.

Use feof or ferror to determine whether an error occurred.

Remarks

The fgets function reads a string from the input stream argument and stores it in string.

fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n – 1, whichever comes first.

The result stored in string is appended with a null character.

The newline character, if read, is included in the string.

fgetws is a wide-character version of fgets.

fgetws reads the wide-character argument string as a multibyte-character string or a wide-character string according to whether stream is opened in text mode or binary mode, respectively.

For more information about using text and binary modes in Unicode and multibyte stream-I/O, see Text and Binary Mode File I/O and Unicode Stream I/O in Text and Binary Modes.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE Defined
_fgetts fgetws

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

/* FGETS.C: This program uses fgets to display
 * a line from a file on the screen.
 */

#include <stdio.h>

void main( void )
{
   FILE *stream;
   char line[100];

   if( (stream = fopen( "fgets.c", "r" )) != NULL )
   {
      if( fgets( line, 100, stream ) == NULL)
         printf( "fgets error\n" );
      else
         printf( "%s", line);
      fclose( stream );
   }
}

Output

/* FGETS.C: This program uses fgets to display

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also

fputs | gets | puts

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.