0

What wrong in this code?

#include <stdio.h> int main() { int n,num,i; FILE *fp, *fpo, *fpe; fp=fopen("main.dat","w"); printf("how many numbers?"); scanf("%d",&n); printf("enter the number now"); for(i=0;i<n;i++) { scanf("%d",&num); putw(num,fp); } fclose(fp); fp=fopen("main.dat","r"); fpo=fopen("odd.dat","w"); fpe=fopen("even.dat","w"); for(i=0;i<n;i++) { num=getw(fp); if(num==0) putw(num,fpe); else putw(num,fpo); fp=fopen("main.dat","r"), printf("content from main file"); while(num=getw(fp)!=EOF) printf("%d\t",num); fclose(fp); fp=fopen("odd.dat","r"); printf("content from odd file"); while(num=getw(fpo)!=EOF) printf("%d\t",num); fclose(fpe); fp=fopen("even.dat","r"); printf("content from even file"); while(num=getw(fpe)!=EOF) printf("%d\t",num); fclose(fpe); return 0; }

3rd Jan 2022, 1:12 PM
Ganesh Neupane
Ganesh Neupane - avatar
1 Answer
+ 6
putw() and getw() are not part of standard C so you may not be able to use them freely in any compiler. https://stackoverflow.com/questions/33692411/putw-function-in-c By your condition, only zeros will be considered as even, other numbers are considered odd. Reconsider that logic. And Idk why you open and reopen file pointers inside the second for...loop. You may gain more attention if you posted an MWE (minimum working example). Here you posted a wall of text, code with no indentation or formatting. FYI it is lots harder to analyze such codes, and people will less likely even look. https://www.sololearn.com/post/75089/?ref=app
3rd Jan 2022, 1:57 PM
Ipang