fgetws

Reads a line of wide characters from a specified file.

Format

#include  <wchar.h>

wchar_t *fgetws  (wchar_t *wstr, int maxchar, FILE
                 *file_ptr);
Function Variants This function also has variants named _fgetws32 and _fgetws64 for use with 32-bit and 64-bit pointer sizes, respectively. See Section 1.8 for more information on using pointer-size-specific functions.

Arguments

wstr
A pointer to a wide-character string large enough to hold the information fetched from the file.
maxchar
The maximum number of wide characters to fetch.
file_ptr
A file pointer.

Description

This function reads wide characters from the specified file and stores them in the array pointed to by wstr. The function reads up to maxchar-1 characters or until the newline character is read, converted, and transferred to wstr, or until an end-of-file condition is encountered. The function terminates the line with a null wide character. fgetws places the newline that terminates the input line into the user buffer, unless maxchar characters have already been fetched.

Return Values
Pointer to wstr
NULL  Indicates the end-of-file or an error occurred. The contents of wstr are undefined if a read error occurs. If a read error occurs, the function sets errno. For a list of possible errno values, see fgetwc in this section. 

Example

    #include <stdlib.h>
    #include <stdio.h>
    #include <locale.h>
    #include <wchar.h>
    
    main()
    {
        wchar_t wstr[80], *ret;
        FILE *fp;
    
        /* Open a test file containing : "THIS IS A TEST." */
    
        if ((fp = fopen("file.dat", "r")) == (FILE*) NULL) {
            perror ("File open error");
            exit(EXIT_FAILURE);
        }
    
        ret = fgetws(wstr, 80, fp);
        if (ret == (wchar_t *) NULL) {
            perror ("fgetws failure");
            exit(EXIT_FAILURE);
        }
    
        fputws(wstr,stdout);
    
        fclose(fp);
    }
    


Previous Page | Next Page | Table of Contents | Index