C putw() function is used to write an integer to a file. This tutorial guides you on how to use the putw() function in the C program.



Syntax:

int putw( int c, FILE * stream );

Example:

int main (void)
{
    FILE *fileName;
    int i=2, j=3, k=4, n;
    fileName = fopen ("anything.c","w");
    putw(i, fileName);
    putw(j, fileName);
    putw(k, fileName);
    fclose(fileName);

    fileName = fopen ("test.c","r");
    while(getw(fileName)! = EOF)
    {
        n= getw(fileName);
        printf("Value is %d \t: ", n);
    }
    fclose(fp);
    return 0;
}


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram