> Didn't get the output of the program?

Didn't get the output of the program?

Posted at: 2014-12-18 
After writing to the files you need to close them:

fclose(fptr_e);

fclose(fptr_o);

Then re open them for reading:

fptr_e=fopen("C:/TCWIN45/BIN/even.cpp",...

fptr_o=fopen("C:/TCWIN45/BIN/odd.cpp","...

Read the data, then close them again.

#include

#include

#include

main()

{

int n=0,i,n1;

char ch;

FILE *fptr,*fptr_e,*fptr_o;

clrscr();

fptr=fopen("C:/TCWIN45/BIN/all_num.cpp","w");

fptr_e=fopen("C:/TCWIN45/BIN/even.cpp","w");

fptr_o=fopen("C:/TCWIN45/BIN/odd.cpp","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:/TCWIN45/BIN/even.cpp","r");

while(1)

{

ch = fgetc(fptr_e);

if(ch==EOF)

break;

printf("%c\t",ch);

}

fptr_o=fopen("C:/TCWIN45/BIN/odd.cpp","r");

while(1)

{

ch = fgetc(fptr_o);

if(ch==EOF)

break;

printf("%c\t",ch);

}

fclose(fptr_e);

fclose(fptr_o);

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

i got the problem.The problem is it shows the correct output until "even number" line...it shows the output but does not shows the value.why?help me pls.i even add the image of the output which i want.