Export (0) Print
Expand All
div
eof
Expand Minimize

_fgetc_nolock, _fgetwc_nolock 

Reads a character from a stream without locking the thread.


int _fgetc_nolock( 
   FILE *stream 
);
wint_t _fgetwc_nolock( 
   FILE *stream 
);

Parameters

stream

Pointer to the FILE structure.

_fgetc_nolock and _fgetwc_nolock are identical to fgetc and fgetwc, respectively, except that they are not protected from interference by other threads. They might be faster because they do not incur the overhead of locking out other threads. Use these functions only in thread-safe contexts such as single-threaded applications or where the calling scope already handles thread isolation.

Generic-Text Routine Mappings
Tchar.h routine _UNICODE and _MBCS not defined _MBCS defined _UNICODE defined

_fgettc_nolock

_fgetc_nolock

_fgetc_nolock

_fgetwc_nolock

Function Required header Compatibility

_fgetc_nolock

<stdio.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_fgetwc_nolock

<stdio.h> or <wchar.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For more compatibility information, see Compatibility in the Introduction.

// crt_fgetc_nolock.c
// This program uses getc to read the first
// 80 input characters (or until the end of input)
// and place them into a string named buffer.


#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   FILE *stream;
   char buffer[81];
   int  i, ch;

   // Open file to read line from: 
   if( fopen_s( &stream, "crt_fgetc_nolock.txt", "r" ) != 0 )
      exit( 0 );

   // Read in first 80 characters and place them in "buffer":
   ch = fgetc( stream );
   for( i=0; (i < 80 ) && ( feof( stream ) == 0 ); i++ )
   {
      buffer[i] = (char)ch;
      ch = _fgetc_nolock( stream );
   }

   // Add null to end string 
   buffer[i] = '\0';
   printf( "%s\n", buffer );
   fclose( stream );
}

Line one.
Line two.

Output

Line one.
Line two.

Community Additions

ADD
Show:
© 2014 Microsoft