int main2()
{
int fd = open("BTree.c", O_RDONLY, 0777);
if (fd == -1)
{
perror ("open");
return -1;
}
char buf[SIZE] = {0};
while (1)
{
ssize_t ret = read(fd, buf, SIZE-1);
if (ret == -1)
{
perror ("read");
}
// 返回值为0 代表读到文件结尾
if (ret == 0)
{
printf ("文件读取结束\n");
break;
}
//printf ("len = %d\n", strlen(buf));
// printf ("读到 %d 字节: %s\n", ret, buf);
printf ("%s", buf);
}
return 0;
}
{
int fd = open("BTree.c", O_RDONLY, 0777);
if (fd == -1)
{
perror ("open");
return -1;
}
char buf[SIZE] = {0};
while (1)
{
ssize_t ret = read(fd, buf, SIZE-1);
if (ret == -1)
{
perror ("read");
}
// 返回值为0 代表读到文件结尾
if (ret == 0)
{
printf ("文件读取结束\n");
break;
}
//printf ("len = %d\n", strlen(buf));
// printf ("读到 %d 字节: %s\n", ret, buf);
printf ("%s", buf);
}
return 0;
}