比较两个文件内容

| January 3, 2008 18:51 | timmy | Via Original

#include <stdio.h>
#include <stdlib.h>
void main()
{
  FILE *f1,*f2;
  int l,c;
  char ch1,ch2;
  if((f1=fopen("f1.txt","r"))==NULL){
    printf("File open error\n");
    exit(0);
  }
  if((f2=fopen("f2.txt","r"))==NULL){
    printf("File open error\n");
    exit(0);
  }
  l=c=1;
  while(!feof(f1)&&!feof(f2)){
    ch1=fgetc(f1);
    ch2=fgetc(f2);
    if(ch1!=ch2)
      break;
    else
      c++;
    if(ch1=='\n'){
      c=1;
      l++;
    }
  }
  if(fclose(f1)){
    printf("can't close file\n");
    exit(0);
  }
  if(fclose(f2)){
    printf("can't close file\n");
    exit(0);
  }
  printf("l=%d,c=%d\n",l,c);
}
Tags:
Program/Code » C/C++ | Comments(0) | Trackbacks(0) | Reads(189)
Add a comment
 Site URI
 Email
  Password Optional
 Nickname  *  [Register]
               

 
Emots
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
Enable HTML
Enable UBB
Enable Emots
Hidden
Remember