大宇私人领地伊甸园丨宁愿做了后悔,也不要错过后悔[www.mrdayu.com]
注册

24小时联系邮箱:[email protected]

所有文章
大宇私人伊甸园: 首页 > 所有文章 > 编程人生 > C/C++语言 > C标准库详解 > puchar函数详解[正确版]


友情链接:


puchar函数详解[正确版]

发布时间:2018/12/04 C标准库详解 标签puchar阅读:32

原型:

extern int putchar(char c);
error: extern void putchar(char c);

the character is converted to unsigned char just before being writen.

等效于:

putc(ch,stdout).

头文件:

#include <stdio.h>

返回值:

On success:return the written character.

On Failure:return EOF and error indicator (see ferror() function)on stdout.

标准适合范围:

C89/C90 std (ISO/IEC 9899:1990)

C99 std (ISO/IEC 9899:1999):(p:299)

C11 std (ISO/IEC 9899:2011):(p:333)

Linux平台测试:

#include <stdio.h>

int main(){
        int ret_code=0;
        char c;
        for(c='a';((ret_code!=EOF)&&(c!='z'));c++){
                ret_code=putchar(c);
        }
        putchar('\n');
        return 0;
}

输出结果:

[[email protected] STDC]$ gcc stdc_puchar.c
[[email protected] STDC]$ ./a.out 
abcdefghijklmnopqrstuvwxy

Windows平台测试:

#include <stdio.h>

int main(){
	int ret_code = 0;
	char c;
	for (c = 'a'; ((ret_code != EOF) && (c != 'z')); c++){
		ret_code = putchar(c);
	}
	putchar('\n');
	int r = 0x1070;
	printf("\n0x%x\n",r);
	r = putchar(r);
	printf("\n0x\n", r);
	getchar();
	return 0;
}

运行结果:

abcdefghijklmnopqrstuvwxy
0x1070
p
0x

结论:

putchar return calue is not equal to the argument.

The bottom line, for me, is simple.

Let’s hope it doesn’t take 500 years for a discipline of testing to becomes the standard for software developers.

From:dayu

您好!请登录

合作网站快捷登录:
点击取消回复

已有0评论

    大宇博客

    点击这里给我发消息 点击这里给我发消息 点击这里给我发消息 点击这里给我发消息