#include //program to replace repeated numbers with whitespace without changing positions of numbers char copy(char c); //to create a copy of file.txt to check duplicates int find(int *pos); //to find and return numbers int numofdig(int n); int overwrite(int ow); //to replace duplicate numbers with whitespace int main(){ int val1 = 0, val2 =1; int loc,dig; //to store where scanning was left char c; //to create a duplicate text file to check FILE *fp1, *fp2; //file pointers fp1 = fopen("file.txt","r+"); //opening files fp2 = fopen("abc.txt","w+"); copy(c); //run copy function val1 = find(&loc); //run find function printf("%d,%d,%d\n",val1,loc,&loc); dig=numofdig(val1); //find number of digits loc=loc-dig; //return back to position of number start overwrite(loc); //overwrite function fclose(fp1); //closing files fclose(fp2); } char copy(char c){ //copy function FILE *fp1, *fp2; fp1 = fopen("file.txt","r+"); //opening files fp2 = fopen("abc.txt","r+"); c = fgetc(fp1); //creating duplicate of file.txt while (c != EOF) { fputc(c, fp2); c = fgetc(fp1); } fclose(fp1); //closing files fclose(fp2); } int find(int *pos){ int val=0, val1, val2; //declaring integers for the function FILE *fp1, *fp2; //fiile pointers fp1 = fopen("abc.txt", "r"); //opening files fp2 = fopen("file.txt", "r"); while((fscanf(fp1, "%d", &val)) != EOF){ //a loop to look for a meaningful number, //while skipping whitespace if(val == ' ') continue; else val1 = val; if(val != ' ') break; } *pos = ftell(fp1); //taking the current position via ftell function val = 0; fseek(fp2, *pos, SEEK_SET); //using fseek to navigate in the file and skip while((fscanf(fp2, "%d", &val)) != EOF){ //to look where scanning was left, if(val == ' ') continue; //meanwhile looking if there is a repeating number else val2 = val; if(val1 == val2) break; } *pos = ftell(fp2); //updating the position fclose(fp1); //closing files fclose(fp2); if(val1 == val2) return val1; //returning value else return -1; } int numofdig(int n){ //a simple function to get digits of a number int counter=0; while(n!=0) { n=n/10; counter++; } return counter; } int overwrite(int ow){ //function to overwrite when repeating numbers are found char a; FILE *fp; fp = fopen("file.txt", "w+"); fseek(fp, ow, SEEK_SET); while((a=fgetc(fp)) != EOF && (a != 32)) fputc(32,fp); fclose(fp); }