Professional Documents
Culture Documents
To Add and Append The Data
To Add and Append The Data
Insurance accept_data();
Void main()
{
char reply;insurance p;
insurance accept_dat();
FILE *fp;
Printf(\n Adding Records );
Fp=fopen(insurance.dat,ab);
If(fp==null)
{
printf(\n Error in Appending the Data:):
exit(1);
}
do
{
p=accept_dat();
fwrite(&p,sizeof(p),1,fp);
printf(\n\n Add another Record ? [Y/N]);
fflush(stdin);
reply=getchar();
}
while(reply==y|| reply==y);
fclose(fp);
}
insurance accept_data()
{
insurance x;
printf(\n Enter insurance no);
scanf(%d,&x.ins_no);
printf(\n Enter name of the person);
scanf(%s,,x.name);
printf(\n Date of insurance dd-mm-yyyy);
scanf(%d-%d-%d,&x do %d,&x.doi.m,&x.doi.y);
printf(\n Amount Insured );
scanf(%f,&x.amt);
return(x);
}
if(strcmp(p.name,name)==0)
{
printf(\n record found\t Record No :%d ,record_no);
printf(\n Enter the modified dat\n);
p=accept_data();
record_no--;
fseek(fp,record_no*sizeof(fp),0);
fwrite(&p,sizeof(p),1,fp);
break;
}
}
/* End of While */
rewind(fp);
printf(\n modify another Record [y/n]?);
fflush(stdin);
reply=getchar();
}
while(reply==y||reply==y);
fclose(fp);
}
/* End of main and Modify a record */
scanf(%d,&choice);
if(query(choice)==0)
printf(\n Record not found try again);
printf( u want query again [y/n]);
reply=getchar();
}
while(replay==y||replay==y);
}/* end of list records main */
int query(int y)
{
FILE *fp;
Insurance r,x;
Fp=fopen(insurance.dat,rb);
If(fp==null)
{
printf(\n Error in opening the file );
return(0);
}
if(y==1)
{
printf(\n Enter the Insurance No :);
scanf(%d,&r.ins_no);
rewind(fp);
while(fread(&x,sizeof(x),1,fp)==1)
{
if(x.ins_no==r.ins_no)
{
printf(\n Found \n Displaying the dat .);
display_data(x);
break;
}/* end of while */
}/* End of if For */
if(y==2)
{
printf(\n Enter name);
scanf(%s,&r.name);
rewind(fp);
while(fread(&x ,sizeof(x),1,fp1)==1)
{
if(strcmp(x.name,r.name)==0)
{
printf(\n Found \n Displaying the data);
display_data(x);
break;
}
}
/*end of while*/
}
/* End of if-for y=2 */
if(y==3)
{
printf(\n Enter Date of Insurance);
scanf(%d-%d-%d,&r.doi.d, &r.doi.m, &r.doi.y);
rewind(fp);
while(fread(&x ,sizeof(x),1,fp1)==1)
{
if(x.doi.y==r.doi.y)
if(x.doi.m==r.doi.m)
if(x.doi.d==r.doi.d)
{
printf(\n Found \n Displaying the data);
display_data(x);
break;
}
}
/*end of while*/
}
/* End of if-for y=3 */
if(feof(fp))
{
fclose(fp);
return(0);
}
fclose(fp);
return(1);
}
Char c;
Fp=fopen(argv[1],r);
If(fp=null)
{
printf(\n File not found);
exit(1);
}
while(! Feof(fp))
{
c=getc(fp);
putchar;
}
fclose(fp);
}