I want to update information i previously stored on a file but cannt do.
My code is

//-----------------------------

//--------------------------------"s"-Structure created--------------------
struct student
{
char regno[20];
//----------------------Pinfo var------------------
char name[50],gender[7],dob[20],otno[20],colg[50],branch[20],hno[10];
int rno;
//----------------------Einfo var------------------
char doj[10];
float teage,twage;
//----------------------Painfo var-----------------
char fname[20],occ[50],ladd[100],cadd[100],ftno[20];
//----------------------Payinfo var----------------
char payj[200],dues[200],smoney[200],mode[20];
//----------------------Remarks var----------------
char remark[900];
//----------------------Marks var------------------
int marks[8],hmarks[8];
//----------------------Event var------------------
char evntname[100];
int evntno;
}s;
//--------------------------------Update----------------------------

void update(int x)
{
FILE *fp;
char name[20],regno[20],ter;
int n,choice,m=0;
clrscr();
if(x==0)
{
do
{
fp=fopen("Student.txt","r+");
printf("\n\nEnter Regno::");
flushall();
gets(regno);
while((fread(&s,sizeof(s),1,fp))==1)
{
n=strcmpi(regno,s.regno);
if(n==0)
{
printf("\n\nWhat Do you want to update?\n1:Personal Information\n2:Educational Information\n3:Parental Information\n4:Payment details\n5:Marks\n6:Remarks\n7:Events\n8:Re-Enter full information\nEnter Your Choice::");
scanf("%d",&choice);
switch(choice)
{
case 1:
pinfo();
break;
case 2:
einfo();break;
case 3:
painfo();break;
case 4:
payinfo();break;
case 5:
marks();break;
case 6:
remarks();break;
case 7:
events();break;
case 8:
add(x);
break;
default:
printf("\n\nYou Entered Wrong choice");
}
fwrite(&s,sizeof(s),1,fp);
m=1;
}
}
if(m==0)
printf("\n\nReg. no. You Entered doesnot match");
fclose(fp);
printf("\n\nDo You Want To Re-Search A Student?(y/n)");
ter=getch();
}while(ter=='y'||ter=='Y');
}
if(x==1)
{
printf("\n\nFaculty");
}
if(x==2)
{
printf("\n\nStaff");
}
}
//--------------------------------------------------------------------

I want to know how can i update the information stored previously........

Recommended Answers

All 2 Replies

Format your code so we can follow it.
Then tell us what's happening, don't make us guess.

Just a thought ... I think this might help you ...

When you use a file for storing data you cannot just update a single line of text in that file. You have to read the entire file into memory, make the changes that you want in the memory and then write out the modified memory back into the file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.