给文件写数据

#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

char buffer[] = "look the sample!";

void main( void )
{
 int fh;
 unsigned byteswritten;

 if( (fh = _open( "G:\\write.txt", _O_RDWR | _O_CREAT,
  _S_IREAD | _S_IWRITE )) != -1 )
 {
  if(( byteswritten = _write( fh, buffer, sizeof( buffer ))) == -1 )
   perror( "Write failed" );
  else
   printf( "Wrote %u bytes to file\n", byteswritten );

  _close( fh );
 }
}


 

posted @ 2011-12-24 18:26  rookieeeeee  阅读(132)  评论(0编辑  收藏  举报