printf and wprintf in single C code

后端 未结 2 1471
天涯浪人
天涯浪人 2020-12-30 00:26

I have a problem when using printf and wprintf functions together in code. If the regular string is printed first, then wprintf doesn\

2条回答
  •  太阳男子
    2020-12-30 01:27

    To complement R..'s accepted answer:

    While this is very rarely done, checking the return code of printf/wprintf would more clearly indicate that one of them is not working (it should return -1 for the print function which is invalid according to the current orientation of the stream).

    Unfortunately, a common pattern for checking errors in standard library functions:

    if (wprintf(...) == -1) { perror("wprintf"); ... }
    

    May not help much here: if the stream is set to output non-wide characters, and you call wprintf, errno may not be set and you'll get wprintf: Success, which does not provide much information.

    So indeed this is a somewhat hard to understand issue when you don't know about the character orientation of streams.

提交回复
热议问题