Reputation: 23
Following program with putw is not writing the required data in the file.
#include <stdio.h>
int main(void)
{
FILE *fp;
fp = fopen("a.txt", "w");
putw(25,fp);
putw(325,fp);
putw(425,fp);
fclose(fp);
return 0;
}
Program is compiled and executed like the following
gcc filename.c
./a.out
It is writing something in the file. Also if we read the integer using getw()
, it is reading the value which is not available in the file. Even it is not the ASCII value.
When it is compiled with gcc filename.c -std=c99
, it is showing implicit declaration warning error.
Is it required to link any library files to use putw/getw in c.
Upvotes: 0
Views: 2030
Reputation: 59623
putw
is an ancient function that exists on some platforms. Use fwrite
and fread
instead. You should also check the return value from putw
. It may be telling you why it is failing.
Upvotes: 1
Reputation: 214780
There is no function called putw
in standard C, which is why you get compiler warnings. You probably meant to use putwc
in wchar.h
.
Upvotes: 1