#include <wchar.h>
|
wchar_t *
getws (wchar_t * restrict ws); |
The getws function is equivalent to fgetws with an infinite size and a stream of stdin, except that the wide character newline(if any) is not stored in the string. It is the caller’s responsibility to ensure that the input line, if any, is sufficiently short to fit in the string.
#include <stdio.h> #include <wchar.h> /* Illustrates how to use getws API */ int example_getws() { FILE* stdop = freopen("c:\stdop","w+",stdout); FILE* stdip = freopen("c:\stdip","w+",stdin); FILE* stder = freopen("c:\stder","w+",stderr); wchar_t* buf = (wchar_t*)malloc(sizeof(wchar_t)*50); wchar_t s[100]; int ret = 0; size_t size = fwrite("abdcef\n", 1, 6, stdip); //write to stdin fclose(stdip); stdip = freopen("c:\stdip","r", stdin); getws(s); // read a line (from stdin) putws(s); //write to stdout fclose(stdop); stdop = freopen("c:\stdop","r", stdout); fgetws(buf,7,stdop); //read from stdout if(wcsncmp(s, buf,6)) { ret = -1; } fclose(stdin); fclose(stder); fclose(stdop); remove("c:\stdop"); remove("c:\stdip"); remove("c:\stder"); return ret; }
Output
abcdef abcdef
[EFAULT] | |
The given ws argument is NULL. | |
The function getws may also fail and set errno for any of the errors specified for the routines fflush, fstat, read, fgetws, or malloc.
© 2005-2007 Nokia |