6.23.8 fgetws Function
Obtains wide string input from a stream.
Include
<wchar.h>
Prototype
wchar_t * fgetws(wchar_t * restrict s, int n, FILE *
stream);
Arguments
s
- the wide array in which to store the string
n
- the maximum number of bytes written to the array
stream
- the stream to read input from
Return Value
After a successful read, the function returns s
. If end-of-file is
encountered and no characters have been read into the array, the the array is not modified and
a null pointer is returned. If a read or encoding error occurs during the operation, the array
contents are indeterminate and a null pointer is returned.
Remarks
This function reads no more than n
-1 wide characters from the stream,
terminating once encountering a new-line wide character or and end-of-file. A null wide
character is written to the array after those wide characters read from the stream.
Example
#include <wchar.h>
#include <stdio.h>
int main(void)
{
FILE * myfile;
wint_t ws[30];
if ((myfile = fopen("afile", "r")) == NULL)
wprintf(L"Cannot open afile\n");
else
{
if(fgetws(ws, 30, myfile) == NULL)
wprintf(L"String read returned error\n");
else
wprintf(L"Your string: %ls\n", ws);
fclose(myfile);
}
}
Example Input
Content of afile
.
Four and 20
Example Output
Your string: Four and 20