Hi !!,
I am trying to write a file writing program. This program writes the data to a text file. I wanted it to keep doing so till i tell it to exit. The code compiles without a problem, but after i input the data i get a message saying that this operation has to be terminated or something like that. Please help
#include <stdio.h>
main()
{
int num;
struct test
{
char memname [10];
char memadd [40];
int ph;
int age;
char sex;
}info;
/*
the file should be opened at this stage*/
//fflush(stdin);
for (num=1;num<num+1;num++)
{
FILE *fp;
fp=fopen("member.txt","a+");
printf ("\n\t\t\tENTER MEMBER NO. :%d:\t\t\t\n",num);
printf ("\nEnter the Member's Name : \n");
scanf("%s",info.memname);
printf ("\nEnter the Member's Address : \n");
scanf ("%s",info.memadd);
printf ("\nEnter the Phone Number : \n");
scanf ("%d",&info.ph);
printf ("\nEnter the Age of the Member : \n");
scanf ("%d",&info.age);
fflush (stdin);
printf ("\nEnter the gender of the Member : \n");
scanf ("%c",&info.sex);
printf ("----MEMBER NO :%d:----\n\nName : %s\nAddress : %s\nAge :%d\nPhone Number :%d\nGender :%c\n",num,info.memname,info.memadd,info.age,info. ph,info.sex);
fprintf (fp,"\n\n\t----MEMBER NO :%d:----\t\nName : %s\nAddress : %s\nAge :%d\nPhone Number :%d\nGender :%c\n",num,info.memname,info.memadd,info.age,info. ph,info.sex);
system ("cls");
fclose (fp);
}
system("PAUSE");
return 0;
}