Implement more Commands yourself

Source: Internet
Author: User

1#include <stdio.h>2#include <stdlib.h>3 4 #definePagelen 245 #defineLinelen 5126 7 intSee_more (file*);8 voidDo_more (file*);9 Ten intMainintAcChar*av[]) One { AFILE *FP; -     if(ac==1) - Do_more (stdin); the     //printf ("%s", "Please input file name.\n"); -     Else -     {     -          while(--AC) +         if(Fp=fopen (*++av,"R"))!=NULL) -         { + Do_more (FP); A fclose (FP);  at         } -     } -      -              - } -  in voidDo_more (file*FP) - { to     intnum_of_lines=0; +     CharLine[linelen]; -     intreply; the //int See_more (); *file*Fp_tty; $Fp_tty=fopen ("/dev/tty","R");Panax Notoginseng     if(Fp_tty==null) Exit (1); -      while(Fgets (LINE,LINELEN,FP)) the     { +         if(num_of_lines==Pagelen) A         { thereply=See_more (fp_tty); +             if(reply==0) -                  Break; $num_of_lines-=reply; $         } -         if(fputs (line,stdout) = =EOF) -Exit1); thenum_of_lines++;  -     }Wuyi  the } -  Wu intSee_more (file*cmd) - { About     intC; $     //printf ("\033[7m more? \033[m "); -printf"\033[32;49;1m [more?] \033[39;49;0m"); -     //033[32;49;1m [more?] \033[39;49;0m -      while((c=getc (cmd))! =EOF) A     { +         if(c=='Q') the             return 0; -          $         if(c=='\ n') the             return 1; the          the         if(c==' ') the             returnPagelen; -     } in}

Implement more Commands yourself

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.