zoukankan      html  css  js  c++  java
  • 5.1对终端进行读写

    几个小知识点:

    字符串数组作为参数。

    fileno(stdout)的使用。

    标准输出是否被重定向了   isatty( fileno(stdout) );

    回车符的过滤方法。

    #include <stdio.h>
    #include <stdlib.h>

    char *menu[] = {
      "a add",
      "b back",
      "c cancel",
      "q quit",
      NULL
    };

    //函数参数类型

    static int getChoice(char* str, char* menu[])
    {
      int choose;
      int c;
      char** p = NULL;
      int select = 0;

      do{
          select = 0;
          printf("%s ", str);

          p = menu;
          while(*p)
          {
            printf("%s ", *p);
            p++;
          }

          //过滤掉输入的回车符

          do{
              choose = getchar();
           }while(choose == ' ');


          p = menu;
          while(*p)
          {
            if(*p[0] == choose)
            {
              select = 1;
              break;
            }

            p++;
          }

          if(!select)
          {
            printf("incorrect input ");
          }


      }while(!select);


      return choose;
    }

    int main()
    {

      int choose;

      do{

          choose = getChoice("Please input command", menu);
          printf("you have choose %c ", choose);
      }while(choose != 'q');

      exit(0);
    }

  • 相关阅读:
    [转]SVN服务器搭建和使用(二)
    [转]SVN服务器搭建和使用(一)
    BZOJ 2049 Sdoi2008 Cave 洞穴勘测
    BZOJ 1589 Usaco2008 Dec Trick or Treat on the Farm 采集糖果
    BZOJ 2796 POI2012 Fibonacci Representation
    BZOJ 2115 Wc2011 Xor
    BZOJ 3105 CQOI2013 新Nim游戏
    BZOJ 2460 Beijing2011 元素
    BZOJ 3687 简单题
    BZOJ 1068 SCOI2008 压缩
  • 原文地址:https://www.cnblogs.com/zhangxuan/p/5319697.html
Copyright © 2011-2022 走看看