⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conductoranddriver.txt

📁 一个LINUX下的C程序
💻 TXT
字号:
#include<unistd.h>   
  #include<sys/wait.h>   
  #include<sys/types.h>   
  #include<stdlib.h>   
  #include<signal.h>   
  #include<stdio.h>   
  #include<time.h>   
  #define   SIZE   10   
  unsigned   int   seed=(unsigned   int   )time(NULL);   
  int     ntimes=0;   
  int   n;   
  char   ch;   
  void   conducter();   
  void   driver();   
  int   main(int   argc,char   *argv[]){   
          srand(seed);   
          static   struct   sigaction   act;   
          void   catchint(int);   
          act.sa_handler=catchint;   
          sigfillset(&(act.sa_mask));   
          sigaction(SIGINT,&act,NULL);   
          while(true){   
          sleep(1);   
          driver();   
          sleep(1);   
          conducter();   
          }   
  return   0;   
  }   
  void   catchint(int   signo){   
          ch=getchar();   
          switch   (ch){   
          case   'q':   exit(0);   
          case   'c':   printf("there   are   %d   passengers   in   the   bus\n",SIZE-n);sleep(1);   
        }   
  }   
  void   conducter(){
      int i;   
      int   number=rand()%SIZE;   
      printf("there   are   %d   people   to   get   down.\n",number);   
      for(int   i=0;(i<number)&&(n<SIZE);++i){   
        printf(".");   
        n++;   
      }   
      sleep(1);   
      number=rand()%SIZE;   
      printf("\nthere   are   %d   people   to   get   up.\n",number);   
      for(i=0;(i<number)&&(n>0);++i){   
        printf(".");   
        n--;   
      }   
      printf("\nthe   bus   door   is   going   to   be   closed.\n");   
      sleep(1);   
      printf("bus   door   has   been   closed,bus   begins   to   run.\n\n");   
  }   
    
  void   driver(){
      int   i;   
      printf("bus   is   running.\n");   
      sleep(1);   
      for(i=0;i<10;++i){   
      printf(".");   
      }   
      printf("\nbus   is   going   to   stop.\n");   
      sleep(1);   
      printf("the   bus   has   stopped.\n\n");   
  }   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -