I want to find the repeated integers and replace their positions with empty space. This is my homework. But I didn't solve this problem. My code is
int main(){
int control_integer;
int temp_integer;
int flag = 0;
int location;
char space = ' ';
char control_end_of_file;
FILE *fp,*tp;
fp = fopen("file.txt","r+");
while(!feof(fp))
{
fscanf(fp,"%d",&control_integer);
printf("control_integer: %d\n",control_integer );
while(!feof(fp)){
fscanf(fp,"%d",&temp_integer);
printf("temp_integer = %d\n",temp_integer );
if (temp_integer == control_integer)
{
flag = 1;
printf("girdi integer: %d\n",temp_integer );
fprintf(fp, " %c ",space );
}
}
}
return 0;
}
I planned my function as follows. First I take an element in the file, then I go to a new loop and look at the next elements. If it is equal, I want to replace it with a space. But the problem arises right here. * fp
, when the reading operation is performed, the next element is passed but I want to prevent it and write something else to that location. So I want to do both write and delete in the same place. I tried something, but I couldn't do it.