Iharob Al Asimi
Iharob Al Asimi

Reputation: 53006

No output when using `fprintf' after `fwprintf'

This just happened to me while testing a part of a bigger program that I isolated. The original function would remove non ascii characters from a string in a special manner that I needed, the thing is this program

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

int main(int argc, char *argv[])
{
    fwprintf(stdout, L"-- Example\n");
    fprintf(stdout, "-- Example\n");

    return 0;
}

would not print the second -- Example on my linux (Fedora 22) system. Although using fwprintf() again or fprintf(stderr, "-- Example\n"); would work.

Upvotes: 8

Views: 348

Answers (1)

trojanfoe
trojanfoe

Reputation: 122381

I believe this issue might be related to the wide orientation of the file stream. If fwide() is not used then the orientation of the first file function is used to determine the orientation (you can also set the orientation when opening file, but that doesn't apply here).

Once the stream is wide then you need to use wide functions; and when non-wide you need to use non-wide functions.

Once the orientation is set, it cannot be changed.

Upvotes: 2

Related Questions