|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
_fdopen, _wfdopen
FILE *_fdopen( int fd, const char *mode ); FILE *_wfdopen( int fd, const wchar_t *mode );
|
|
|
|
|
|---|---|---|---|
|
_tfdopen |
_fdopen |
_fdopen |
_wfdopen |
|
|
|
|---|---|
|
a |
|
|
a+ |
|
|
r |
_O_RDONLY |
|
r+ |
_O_RDWR |
|
w |
|
|
w+ |
|
|
b |
_O_BINARY |
|
t |
_O_TEXT |
|
c |
|
|
n |
|
|
|
|
|---|---|
|
_fdopen |
|
|
_wfdopen |
|
// crt_fdopen.c
// This program opens a file by using low-level
// I/O, then uses _fdopen to switch to stream
// access. It counts the lines in the file.
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <share.h>
int main( void )
{
FILE *stream;
int fd, count = 0;
char inbuf[128];
// Open a file.
if( _sopen_s( &fd, "crt_fdopen.txt", _O_RDONLY, _SH_DENYNO, 0 ) )
exit( 1 );
// Get stream from file descriptor.
if( (stream = _fdopen( fd, "r" )) == NULL )
exit( 1 );
while( fgets( inbuf, 128, stream ) != NULL )
count++;
// After _fdopen, close by using fclose, not _close.
fclose( stream );
printf( "Lines in file: %d\n", count );
}
Saída