VMS Help  —  CRTL  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);

1  –  Function Variants

    The fgetws function has variants named _fgetws32 and _fgetws64
    for use with 32-bit and 64-bit pointer sizes, respectively.

2  –  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.

3  –  Description

    The fgetws 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 new-line 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 new-line that
    terminates the input line into the user buffer, unless maxchar
    characters have already been fetched.

4  –  Return Values

    x                  Pointer to wstr.
    NULL               Indicates the end-of-file or an error. 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.

5  –  Example

        #include <stdlib.h>
        #include <stdio.h>
        #include <locale.h>
        #include <wchar.h>

        main()
        {
            wchar_t wstr[80],
                   *ret;
            FILE *fp;

            /* Create a dummy data file  */

            if ((fp = fopen("file.dat", "w+")) == NULL) {
                perror("open");
                exit(1);
            }

            fprintf(fp, "this is a test\n") ;
            fclose(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);
            delete("file.dat");
        }
Close Help