Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

HANDLING OF INTEGER DATA FILES

Posted By: Finley Evans     Category: C Programming     Views: 4194

HANDLING OF INTEGER DATA FILES.

Code for HANDLING OF INTEGER DATA FILES in C Programming

   #include  <stdio.h>                                               
   main()                                                            
   {                                                                 
       FILE  *f1, *f2, *f3;                                          
       int   number, i;                                              
                                                                     
       printf("Contents of DATA file\n\n");                          
       f1 = fopen("DATA", "w");      /* Create DATA file    */
for(i = 1; i <= 30; i++) { scanf("%d", &number); if(number == -1) break; putw(number,f1); } fclose(f1); f1 = fopen("DATA", "r"); f2 = fopen("ODD", "w"); f3 = fopen("EVEN", "w"); /* Read from DATA file */
while((number = getw(f1)) != EOF) { if(number %2 == 0) putw(number, f3); /* Write to EVEN file */
else putw(number, f2); /* Write to ODD file */
} fclose(f1); fclose(f2); fclose(f3); f2 = fopen("ODD","r"); f3 = fopen("EVEN", "r"); printf("\n\nContents of ODD file\n\n"); while((number = getw(f2)) != EOF) printf("%4d", number); printf("\n\nContents of EVEN file\n\n"); while((number = getw(f3)) != EOF) printf("%4d", number); fclose(f2); fclose(f3); } Output Contents of DATA file 111 222 333 444 555 666 777 888 999 000 121 232 343 454 565 -1 Contents of ODD file 111 333 555 777 999 121 343 565 Contents of EVEN file 222 444 666 888 0 232 454
  
Share: 


Didn't find what you were looking for? Find more on HANDLING OF INTEGER DATA FILES Or get search suggestion and latest updates.

Finley Evans
Finley Evans author of HANDLING OF INTEGER DATA FILES is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!