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

📄 reverse.c

📁 C Primer Plus(第五版)中文版源码,I hope it will help you much
💻 C
字号:
/* reverse.c -- displays a file in reverse order */
#include <stdio.h>
#include <stdlib.h>
#define CNTL_Z '\032'   /* eof marker in DOS text files */
#define SLEN 50
int main(void)
{
    char file[SLEN];
    char ch;
    FILE *fp;
    long count, last;

    puts("Enter the name of the file to be processed:");
    gets(file);
    if ((fp = fopen(file,"rb")) == NULL)
    {                      /* read-only and binary modes */
        printf("reverse can't open %s\n", file);
        exit(1);
    }
    
    fseek(fp, 0L, SEEK_END);        /* go to end of file */
    last = ftell(fp);
/* if SEEK_END not supported, use this instead           */
/*  last = 0;
    while (getc(fp) != EOF)
        last++;
*/
    for (count = last- 1; count >= 0; count--)
    {
        fseek(fp, count, SEEK_SET); /* go backward       */
        ch = getc(fp);
    /* for DOS, works with UNIX */
        if (ch != CNTL_Z && ch != '\r')
            putchar(ch);
    /* for Macintosh            */
    /*  if (ch == '\r')
            putchar('\n');
         else
             putchar(ch)
    */
   }
   putchar('\n');
   fclose(fp);
   
   return 0;
}

⌨️ 快捷键说明

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