Hello. I am working on a program that deletes same lines in a text file.
I already wrote it, but it still doesn't work. Could you please help me to find the mistake?
Thank you.
Code:
#include <stdio.h>
main(){
FILE *f1,*f2;
char oneword[100],filename[25];
int c;
long int i,j;
char *norstring[500000]; /* I count from 1 */
long int currentLength=0;
i=0;
printf("enter filename of the first file -> ");
scanf("%s",filename); /* read the desired filename */
f1 = fopen(filename,"r");
int t;
do {
i=i+1;
c = fscanf(f1,"%s",oneword); /* got one word from the 1st file */
if(i==1){
norstring[1]=oneword;
currentLength=1;
}
if((c==1) && (i>1)){
t=0;
for(j=1;j<=currentLength;j++){
if(norstring[j]==oneword){
t=1;
}
}
if(t==0){
currentLength++;
norstring[currentLength]=oneword;
}
}
}while (c != EOF && i<=(500000)); /* repeat until EOF */
fclose(f1);
f2 = fopen("file9.txt","w");
for(j=1;j<=currentLength;j++){
fprintf(f2,norstring[j]); /* prints it to the file */
fprintf(f2,"\n");
}
fclose(f2);
printf("\n\ndone. file9.txt created. press any key");
getch();
}