질문이 있습니다!~
환찬
번거로우시겠지만 이소스를 공부해야대서요 ㅠㅠ 알기쉽게 주석좀 부탁드립니다#include stdio.h
#include ctype.h
#include stdlib.h
#include string.h
FILE *inFP,*outFP, *outFP2;
main (int argc, char *argv[])
{
char first_name[50];
char last_name[50];
char prim_city[50];
char county[50];
char mail_zip[50];
char phone[50];
char prev_key[50];
char key[50];
int line_no = 0;
int numLeaf;
long cLoc;
if (argc != 4) {
printf(Error\n);
exit(1);
}
numLeaf = (int) atoi(argv[3]);
strcpy(prev_key,-1);
inFP = fopen(argv[1], r);
outFP = fopen(argv[2],w);
outFP2 = fopen(tmp.dat,w);
while (line_no numLeaf) {
cLoc = ftell(inFP);
if (cLoc != (int) cLoc) {
printf(Error\n);
exit(10);
}
fscanf(inFP,%s %s %s %s %s %s ,first_name , last_name, prim_city, county, mail_zip, phone);
fprintf(outFP2,%s %s %s %s %s %s\n ,first_name , last_name, prim_city, county, mail_zip, phone);
strcpy(key,last_name);
if( strcmp(key,prev_key) ){
fprintf(outFP, %s %ld\n,key,cLoc);
strcpy(prev_key,key);
}
line_no++;
if (line_no % 1000 == 0)
fprintf(stdout, processed %d lines\n, line_no);
}
fprintf(stdout, procesed %d lines\n, line_no);
fclose(inFP);
fclose(outFP);
fclose(outFP2);
}