[英]How to force printf to return a negative value in c?
I need to write a C program in which printf
should return a negative value. 我需要编写一个C程序,其中的
printf
应该返回负值。 It should be something like this: 应该是这样的:
#include <stdio.h>
int main()
{
int ret_val;
ret_val = printf(something);
printf("%d", ret_val);
}
The output of this should be a negative number(ret_val should be negative). 此输出应为负数(ret_val应为负)。
Invoke an encoding error: 调用编码错误:
int ret = 0;
ret = printf("%lc", (wint_t) -1);
printf("%d\n", ret);
Redirect stdout
to an invalid handle before doing your printf
. 在执行
printf
之前,将stdout
重定向到无效的句柄。 For example, reopen it in read-only mode 例如,以只读模式重新打开它
freopen("fff", "r", stdout);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.