#include<stdio.h>
int main(void)
{
FILE *fp1=NULL;
FILE *fp2=NULL;
char buffer[100];
char buffer1[100];
char buffer2[100];
int count=0;
int count1=0;
int count2=0;
fp1=fopen(\"1a.txt\",\"r\");
fp2=fopen(\"2a.txt\",\"r\");
while(fgets(buffer,100,fp1))
{
count1++;
}
while(fgets(buffer,100,fp2))
{
count2++;
}
if(count1=count2)
{
while(fgets(buffer1,100,fp1))
{
fgets(buffer2,100,fp2);
if(buffer1==buffer2){
count++;
continue;
}
else break;
}
if(count==count1)
printf(\"두 파일은 같습니다.\");
else
printf(\"두 파일은 다릅니다.\");
}
else
printf(\"두 파일은 다릅니다.\");
system(\"pause\");
}
두 파일이 같은지 다른지 알려주는 프로그램 제가 짜봤는데, 계속 다르다고만 나오네요
어디가 잘못된거죠?
일단 C에서 fgets 쓰면 파일 읽는 지점이 계속 뒤로 밀리는 거 아닌가
(count1=count2) -> == 으로 수정... 옛날에 이프때문에 6시간 골싸맨적있어서 이제 알고리즘 맞는거같은데 안돌면 이프부터 보게되었음..
(count1=count2) -> == 으로 수정... 옛날에 이프때문에 6시간 골싸맨적있어서 이제 알고리즘 맞는거같은데 안돌면 이프부터 보게되었음..
차라리 fseek써서 EOF까지 옮긴다음 ftell써서 길이를 변수에 담고 그 길이를 비교하는데 더 편하겠다 [핡]
아 맞다 그건 파일의 길이지 ㅋㅋ 파일의 내용을 비교할라면 strcmp 써야돼 ㅋㅋ [핡]