Need help with altering info on a txt file
Here is the code I am writing not very good I know but I am a noob programer.
Code:
#include <stdio.h>
#include <stdlib.h>
#define LINE_TO_ALTER 200
int main(int argc, char *argv[])
{
int i=0,Id;
FILE *testfile;
int j=0;
char alter[LINE_TO_ALTER];
char nome[200];
char numero[100];
testfile=fopen("contactos.txt","r+");
printf("Enter the number of the line you want to alter");
scanf("%d",&Id);
while (i<=Id)
{
printf("%d",i);
fscanf(testfile,"%s",&alter);
i++;
}
fseek(testfile,0L,SEEK_CUR);
printf("Alter line");
scanf("%s",&nome);
scanf("%s",&numero);
fprintf(testfile,"\n#%s#%s# \n",&nome,&numero);
fclose(testfile);
system("PAUSE");
return 0;
}
Now using r+ overwrites the text in a file and thus what I am trying to accomplish with this program is overwrite the line of text that I wish to alter and then so that the rest of the txt file is not changed I wanted to also overwrite everything from the line that is being altered with the exact same information that is already in the file from the line that has been altered until the end (hope someone can help me.... and if possible bye using my idea). lol sorry for the redundancy, but I can't seem to find another way to explain. If anyone has doubts in my explanation just ask and I will try to explain again.
Thanks in advance......
Bye the way "nome" is name in portugues
and "numero" is number