博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
5.1对终端进行读写
阅读量:4655 次
发布时间:2019-06-09

本文共 1029 字,大约阅读时间需要 3 分钟。

几个小知识点:

字符串数组作为参数。

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\n", str);

      p = menu;

      while(*p)
      {
        printf("%s\n", *p);
        p++;
      }

      //过滤掉输入的回车符

      do{

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

        p++;

      }

      if(!select)

      {
        printf("incorrect input\n");
      }

  }while(!select);

  return choose;

}

int main()

{

  int choose;

  do{

      choose = getChoice("Please input command", menu);

      printf("you have choose %c\n", choose);
  }while(choose != 'q');

  exit(0);

}

 

转载于:https://www.cnblogs.com/zhangxuan/p/5319697.html

你可能感兴趣的文章
SQL Server 下取中位数(中位值)的方法
查看>>
Using databases and Structured Query Language (SQL)
查看>>
网络对抗作业一
查看>>
路径规划效果图
查看>>
JAVA-注解规范
查看>>
Jmeter下进行ip伪造
查看>>
如何解决SQL Server 2008 无法连接到(local)
查看>>
java 向上转型 向下转型
查看>>
mysql的数据结构
查看>>
【目标流畅阅读文献】kick off
查看>>
Python学习之路-26 Socket
查看>>
mysqldump不得不说的秘密
查看>>
优化Android Studio/Gradle构建(转)
查看>>
DDD领域模型数据访问权限之用户权限(十)
查看>>
VM 的安装与简介
查看>>
[转]PHP 判断数组是否为空的几种方法
查看>>
使用watch定时执行命令并显示结果
查看>>
转载:javaweb学习总结(三十)——EL函数库
查看>>
用matplotlib库画图
查看>>
React Native入门 Enable live Reload
查看>>