C Programming language

adplus-dvertising
Integer I/O : How to use getw( ) Function in C
Previous Home Next

The gettw() function is used to read the integer from file.

int getw(FILE *fp1);

This function return the integer value from the file associated with pointer fp1. it return the next integer from the input files on success and EOF on error.

/** program to understand the use of getw( ) function */

#include<stdio.h>
void main()
{
FILE *fp1;
int a;
fp1=fopen("rajesh.dat","rb");
while((a=getw(fp1)!=EOF)) //Read integer form file
printf("%d\t",a);
fclose(fp1);
};

Output:This program read the integer from the file name "rajesh.dat"

1

2

3

4

5

6

7

8

9

10

Previous Home Next