– putw in c programming is the another file handling function available in c.
– In this tutorial we will see what is mean by putw in c programming,how it is defined and used in file handling function in c.
– putw in c programming :- This function is used to write the integer value to file.
– syntax for using putw function:-
putw(int data,FILE *fp);
In above syntax for putw function, we can see putw function accepts two parameters first is integer data to write to file and second which is file pointer which points to the file.
– Example :-
int data =10;
Where fp is file pointer and data is the integer data which you want to store in file.
– getw function used to read integer data where putw function used for writing integer data to file.
now lets see the program for putw in c programming.
void main ()
data = 10;
printf ("\n opening file in write mode to write integer data:");
fp=fopen ("technical.txt","w"); //opening file in write mode
if(fp == NULL)
printf ("\n can't open file");
printf("\nWrite Integer data to file:");
putw(data,fp); //writing data.
printf("\nData written to file successfully.");
Output :-. (Assume file technical.txt)
- In above program we are writing integer data to file.
- First we open file technical.txt .
- Assume technical.txt exists in current directory location.
- fopen file opens the successfully as it is exist (otherwise fopen creates file with name technical.txt and opens file)
- Next we store integer data to variable data which we want to store to file.
- Write putw function write the integer data to file with two parameter first is data and second is file pointer.
- We written data now close the File. ( This is most important)
- We can see file which contains that data which we stored.
- End with the program