从linux上的/ dev / urandom获取宽字符串

时间:2016-01-17 12:17:12

标签: c linux string random wchar

我试图从/dev/urandom获取一个宽字符串,但STDOUT上没有任何或一些短暂的奇怪结果。我今天需要解决这个问题。请帮我!这有什么不对......

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

int main(){

    setlocale(LC_ALL, "");
    wchar_t text[100];
    FILE *urandom;
    int x = 5;

    urandom = fopen("/dev/urandom", "r");

    while(x--){

        fgetws(text, 100, urandom);
        fwprintf(stdout, L"%ls\n", text);
        //fputws(text, stdout);

    }

    fclose(urandom);

    return 0;

}

编辑:

THIS IS WHAT I SHOULD GET(使用normal char[], fgets, fputs):

THIS IS WHAT I'M GETTING(使用wchar_t[], fgetws, fwprintf/fputws):

0 个答案:

没有答案