hi , getw() is used to read the next INTEGER from a filestream right ?
Assume
-------
My text document has the following
12 i am an 3 4 intern 5 67
Expected output
---------------
Then , i expected that, on running getw() inside a while loop, it would print 12 3 4 5 67
But my code just prints out the entire file.
Please refer to my code below and send me your valuable suggestions
My code
--------
#include<stdio.h>
#include<conio.h>
int main(void)
{
FILE* fp;
int num=0;
clrscr();
fp=fopen("e:\\desktop\\tc1\\bin\\fileh\\numbers.txt","r");
if(fp==NULL)
printf("\nFile could not be opened ");
else
{
printf("\nNumbers are going to be read from the file \n------------------------------------------\n");
while(1)
{
num=getw(fp);
if(num==EOF)
break;
else
{
putw(num,stdout);
}
}
}
printf("\n\nAll numbers from the file have been read ");
getch();
return 0;
}
PS: Yes, i have tried changing the mode to "rb" instead of r as well , as i saw that in a few places.
---
Thank you so much for the help in advance