gpt4 book ai didi

C读函数未定义错误: 0

转载 作者:太空宇宙 更新时间:2023-11-04 01:03:56 25 4
gpt4 key购买 nike

当我调用 c read 函数时,perror 函数告诉我这是一个未定义的错误:0。

这是由于错误而退出的代码片段:

  if( read(fd,&head_data->npts,sizeof(int)) <= 0 )
{
perror("File read error in reading data\n");
exit(1);
}

head_data 是一个结构,npts 是该结构的一个 int 成员。

我查看了 opengroup 和 linux 手册页,但找不到有关未定义错误的任何信息。我不知道这是否有任何区别,但我正在 Mac OS 10.9.5 上编译和运行。

最佳答案

来自read(2) man page :

If successful, the number of bytes actually read is returned. Upon reading end-of-file, zero is returned. Otherwise, a -1 is returned and the global variable errno is set to indicate the error.

所以你只读取了 0 个字节 - 意味着文件结束。

关于C读函数未定义错误: 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28619722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com