LINUX C例程1:open的用法

/* ************************************************************************
* Filename: open.c
* Description:
* Version: 1.0
* Created: 2011年07月18日 18时54分51秒
* Revision: none
* Compiler: gcc
* Author: YOUR NAME (),
* Company:
* ***********************************************************************
*/


#include
<stdio.h>
#include
<stdlib.h>
#include
<unistd.h>
#include
<string.h>
#include
<fcntl.h>


int main(int argc, char *argv[])
{

int fd;
char str[100];

fd
= open("cd.txt",O_RDONLY);

if(fd < 0)
{
perror(
"open");
}

while(read(fd,str,sizeof(str)) > 0)
{
printf(
"%s",str);
}


return 0;
}

  

原文地址:https://www.cnblogs.com/hnrainll/p/2109368.html