Tuesday, November 24, 2009

c file handling program example


/*this program adds two numbers
and save it into a file named sum_rslt.txt*/

#include< stdio.h>
#include< stdlib.h>
void main()
{
FILE *f;
char an='Y';
struct d
{
int a,b,c;
};
struct d e;

f=fopen("sum_rslt.txt","a+");


while(an=='Y')
{
printf("enter first no : ");
scanf("%d",&e.a);
fprintf(f,"\nfirst no : %d",e.a);

printf("\nenter second no : ");
scanf("%d",&e.b);
fprintf(f,"\nsecond no : %d",e.b);

e.c=(e.a+e.b);

fprintf(f,"\nreslt : %d\n\n\n",e.c);

printf("\n\npress Y to do again : ");
fflush(stdin);
an=getche();
printf("\n\n");
}
fclose(f);
}

No comments:

Post a Comment