Hello guys!
I have a question concerning fscanf and fprintf
I do:
/* The format of the id.dat file is : e.g.
1 David Jones
2 Johan Smith
3 Sarlot James
etc...
*/
Code:#include <stdio.h> int main() { int id; char fname[100]; char lname[100]; FILE * fp = fopen("id.dat","r"); fscanf(fp,"%d %s %s",&id,fname,lname); while(!feof(fp)) { printf("%d %s %s\n",id,fname,lname); fscanf(fp,"%d %s %s",&id,fname,lname); /* Here it prints all the elements that are registered in the file */ } /* Now i want to place in the end of the file a new element e.g. 4 John Rino */ /* I do: */ fprintf(fp,"%d %s %s\n",4,"John","Rino"); /* This particular line has to write sthg in the file */ /* of course i have "fopened" the file using "r" read and it's not possible to write in the file, if I i use "w" it destroys everything in the id.dat file */ /* What shall i do in order to write a new element at the end of he file using fprintf? */ } /* main */
Thanks in advance
}



LinkBack URL
About LinkBacks




