|
楼主 |
发表于 2002-8-22 11:23:28
|
显示全部楼层
解决了,下面是个例子:
/*this a test to read a file content*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main (void)
{
char name[20];
char buf[60];
int b;
int c;
int d;
printf ("input the name of the file:");
scanf ("%s",name);
printf ("input the streamsize you want:");
scanf ("%d",&c);
open (name,O_RDONLY);
b=open (name,O_RDONLY);
if (b==-1)
{
printf ("Open Error!\n");
}
read (b,buf,c);
d=read (b,buf,c);
if (d==-1)
{
printf ("Read Error!\n");
}
printf ("the content you want is:\n");
printf ("%s\n",buf);
close (b);
} |
|