Code:
#include <stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int n=0,i,n1;
char ch;
FILE *fptr,*fptr_e,*fptr_o;
clrscr();
fptr=fopen("C:/TCWIN45/BIN/all_num.txt","w");
fptr_e=fopen("C:/TCWIN45/BIN/even.txt","w");
fptr_o=fopen("C:/TCWIN45/BIN/odd.txt","w");
if(fptr==NULL){
printf("Error!");
exit(1);
}
printf("How many record that you want to store : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&n1);
fprintf(fptr,"%d\n",n1);
if(n1%2!=0)
{
fprintf(fptr_o,"%d\n",n1);
}
else
{
fprintf(fptr_e,"%d\n",n1);
}
}
printf("The data are written to the respective file\n\n");
printf("The Even Number are: \t");
fptr_e=fopen("C:/turboc++/even.txt","r");
while(ch=getc(fptr_e)!=EOF)
{
printf("%c\t",ch);
}
fptr_o=fopen("c:/turboc++/odd.txt","r");
while(ch=getc(fptr_o)!=EOF)
{
printf("%c\t",ch);
}
getch();
fclose(fptr);
return 0;
}
And the output which i want is as follows:
How many records that you want to store :4
1
2
3
4
The data are written too the respective files.
The even numbers are 2 4
The odd numbers are 1 3
But it gives some error after entering 1 2 3 4 .Error i got is something "General Protection Exception Processor Fault".Pls tell me why i got this error & how to eliminate it.