文件读写操作

编程完成读出文件中的内容,反序输出到屏幕中
#include<stdio.h>
#include
<stdlib.h>
#include
<conio.h>
#define N 5000

void main()
{
    FILE 
*sfp;
    
int i;
    
char buf[N];
    
if((sfp=fopen("c:\\datafile.txt","r"))==NULL)
    {
        printf(
"Source file cannot be opened!\n");
        exit(
1);
    }
    i
=0;
    
while(!feof(sfp))
    {
        buf[i
++]=fgetc(sfp);
        
if(i>=N)
        {
            printf(
"buffer not enough!");
            exit(
1);
        }
    }
    
while(--i>=0)
        fputc(buf[i],stdout);
    fclose(sfp);
    getch();
}
原文地址:https://www.cnblogs.com/qixin622/p/735423.html