In this tutorial we will see what is mean by getw function, how it is defined and used in file handling function in c.
getw is the another file handling function available in c.
As file contains information , it also contains integer value so to deal with integer type of data getw function is used.
getw function :- This function is used to read the integer value from file.
int int_variable=getw(FILE *fp);
In above syntax for getw() function, we can see getw() function accepts only one parameter which is file pointer which points to the file.and getw() function returns the integer value from file which fp pointing and it returns end of file if file reaches to end of file.
Where fp is file pointer.
Program to demonstrate getw() function in c
void main ()
printf ("\n opening file in read mode to read integer data:");
fp=fopen ("technical.txt","r");. //opening file in read mode
if(fp == NULL)
printf ("\n can't open file");
printf("\n Integer data from file:");
while((data=getw(fp))!=EOF) //read integer data
- In above program we are reading integer data from file.
- First we open file technical.txt .
- Assume technical.txt exists in location with content (content :- 10 20 30).
- fopen file opens the successfully as it is exist (otherwise is prints can’t open file)
- Next we read integer data from file.
- getw function reads the integer data from file and store it to variable data .
- We get integer value till end of file.EOF check whether file reaches end.
Output :-. (Assume file technical.txt with content :- 10 20 30)
opening file in read mode to read integer data:
Integer data from file :