try it, then you know it____________just do it , as love easily fade.

一次只有一个目标,步子迈小些,抑制一次实现所有功能的冲动。 过程如何结果就如何,行动是欢喜的,不管是兴奋还是沮丧的情绪都对结果无益。贵在持之以恒

导航

c 输入输出

__________输出字符串

char str[]="two";  //or

char *str = "two";

puts(str);          //or

printf("%s",str);

__wrong:-------

char **str = "two";

printf("%s",*str);

 

 

 

__________程序的输入都建有一个缓冲区,即输入缓冲区。一次输入过程是这样的,当一次键盘输入结束时会将输入的数据存入输入缓冲区,而cin函数直接从输入缓冲区中取数据。

___!

%d 转换符只针对于 int型数据。

___scanf , getchar

1.before reading character, scanf will not skip empty character.

To force scanf skip the advance space, add a space befor %c

scanf("  %c",&ch); //! 跳过空格符及换行符,制表符

2,getchar 也不会跳过空白字符

2.scanf 会留下后面的字符(包括换行符),只是看一下,并没有读入。如下例中,跳过换行符,避免下次读取错误。

 1     char a;
 2     scanf("%c",&a);
 3 
 4     puts("enter a command");
 5     uchar command;
 6 //    command = getchar();
 7     //skip a line
 8     while( getchar() != '\n')
 9         ;
10 //  same as below line. scanf("%c",&command);      
11     command = getchar();                   
12     printf("%c",command);

 EOF

-,EOF:Windows下以ctrl+Z表示

-,getchar(), scanf("%c", &ch)

The return value is EOF for an error

or if the end-of-file character or the end-of-string character is encountered in the first attempt to read a character. //in the first attemp means, eg, while( (c=getchar())!= EOF) putchar(c);  after input some characters( eg,"hello"),press return key(than you will get output "hello") before you input EOF character, or you will stay in the input state.(from http://blog.csdn.net/hanchengxi/article/details/8591663)

 EOF的值是-1, 所以,上面例子中c必须为有符号类型,否则就是死循环了

 

posted on 2013-04-22 10:37  吾一  阅读(199)  评论(0编辑  收藏  举报