Advertisement
Shailrshah

Odd and Even Numbers from Data.txt

Apr 20th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main()
  5. {
  6.     FILE *fp;
  7.     int i=0,n,a[100],odd,even;
  8.     fp = fopen("C:\\DATA.TXT","r+");
  9.     if(fp==NULL)
  10.     {
  11.         printf("Can't print file");
  12.         exit(1);
  13.     }
  14.     while(1)
  15.     {
  16.         n=getw(fp);
  17.         if(n==EOF)
  18.             break;
  19.         a[i]=n;
  20.         i++;
  21.         putchar(n);
  22.     }fclose(fp);
  23.     printf("The odd terms are:-\n");
  24.     fp=fopen("ODD.TXT","w+");
  25.     for(i=0; a[i]!='\0'; i++)
  26.         if(a[i]%2!=0)
  27.             putw(a[i],fp);
  28.     fclose(fp);
  29.     fp=fopen("ODD.TXT","r");
  30.     while(1)
  31.     {
  32.         odd = getw(fp);
  33.         if(odd == EOF)
  34.             break;
  35.         putchar(odd);
  36.     }fclose(fp);
  37.     fp=fopen("EVEN.TXT","w+");
  38.     for(i=0; a[i]!='\0'; i++)
  39.         if(a[i]%2==0)
  40.             putw(a[i],fp);
  41.     fclose(fp);
  42.     fp=fopen("EVEN.TXT","r");
  43.     while(1)
  44.     {
  45.         even = getw(fp);
  46.         if(even == EOF)
  47.             break;
  48.         putchar(even);
  49.     }fclose(fp);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement