zoukankan      html  css  js  c++  java
  • 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必须为有符号类型,否则就是死循环了

  • 相关阅读:
    msvcr120.dll、msvcp120.dll注册失败
    Qt初级-Qt格式
    二级指针的申请与释放
    搜索指定目录下的所有文件或者指定文件(可用于多级目录)
    Java--多线程处理--模拟车辆进入入收费
    Sqlit--学习教程(建立数据库表)
    Sqlit--学习教程(基本操作1)
    Sqlit--学习教程()
    Sqlit--学习教程(命令)
    Sqlit--学习教程(简介)
  • 原文地址:https://www.cnblogs.com/aprilapril/p/3035047.html
Copyright © 2011-2022 走看看