Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- FILE *fp;
- int i=0,n,a[100],odd,even;
- fp = fopen("C:\\DATA.TXT","r+");
- if(fp==NULL)
- {
- printf("Can't print file");
- exit(1);
- }
- while(1)
- {
- n=getw(fp);
- if(n==EOF)
- break;
- a[i]=n;
- i++;
- putchar(n);
- }fclose(fp);
- printf("The odd terms are:-\n");
- fp=fopen("ODD.TXT","w+");
- for(i=0; a[i]!='\0'; i++)
- if(a[i]%2!=0)
- putw(a[i],fp);
- fclose(fp);
- fp=fopen("ODD.TXT","r");
- while(1)
- {
- odd = getw(fp);
- if(odd == EOF)
- break;
- putchar(odd);
- }fclose(fp);
- fp=fopen("EVEN.TXT","w+");
- for(i=0; a[i]!='\0'; i++)
- if(a[i]%2==0)
- putw(a[i],fp);
- fclose(fp);
- fp=fopen("EVEN.TXT","r");
- while(1)
- {
- even = getw(fp);
- if(even == EOF)
- break;
- putchar(even);
- }fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement