RAD Studio
ContentsIndex
PreviousUpNext
_getw

Header File 

stdio.h 

Category 

Input/output Routines 

Prototype 

int _getw(FILE *stream); 

Description 

Gets an integer from stream. 

_getw returns the next integer in the named input stream. It assumes no special alignment in the file. 

_getw should not be used when the stream is opened in text mode. 

Return Value 

_getw returns the next integer on the input stream.  

On end-of-file or error, _getw returns EOF.

Note: Because EOF is a legitimate value for _getw to return, feof or ferror should be used to detect end-of-file or error.
Example

#include <stdio.h>
#include <stdlib.h>
#define FNAME "test.$$$"
int main(void)
{
FILE *fp;
int word;
/* place the word in a file */
fp = fopen(FNAME, "wb");
if (fp == NULL)
{
printf("Error opening file %s\n", FNAME);
      exit(1);
   }
   word = 94;
   putw(word,fp);
   if (ferror(fp))
       printf("Error writing to file\n");
   else
       printf("Successful write\n");
   fclose(fp);
   /* reopen the file */
   fp = fopen(FNAME, "rb");
   if (fp == NULL)
   {
      printf("Error opening file %s\n", FNAME);
      exit(1);
   }
   /* extract the word */
   word = getw(fp);
   if (ferror(fp))
       printf("Error reading file\n");
   else
       printf("Successful read: word = %d\n", word);
   /* clean up */
   fclose(fp);
   unlink(FNAME);
   return 0;
}

Portability

POSIX 
Win32 
ANSI C 
ANSI C++ 
 
 
 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!