早教吧作业答案频道 -->其他-->
C语言的一道题目?#include#include#include#includeintmain(void){chartest;intfd;if((fd=open("test.dat",ORDONLY))==-1){perror("Cannotopenthetest.datfile");return1;}if(fork()==-1){perror("Cannotcreatethechildproces
题目详情
C语言的一道题目?#include #include #include #include int main(void){ char test; int fd; if((fd=open("test.dat",O_RDONLY))==-1){ perror("Cannot open the test.dat file"); return 1; } if(fork()==-1){ perror("Cannot create the child process"); return 1; } read(fd,&test,1); printf("Process ID: %ld read the character: %c\n",(long)getpid(),test); close(fd); return 0; } 如这个程序所示,其中有几个以为,能否帮忙解释下,第一个if中的return 1是什么意思,open()函数返回的是什么?还有第二个中的干嘛要用fork函数,这其中需要创建进程吗,还有第二个的return 1 的含义。 接下来是最后第四行的read函数,&test代表什么?1代表什么?
▼优质解答
答案和解析
return 是针对你的主函数 为int型,所以必须返回int型返回值。 read(fd,&test,1);read的三个参数是:文件描述符:fd;缓冲区指针:buffer;缓冲区大小:sizeof(buffer) fd是文件句柄,&text指向保存读出的内容的空间,1是大小。 对于open返回值判断,返回值与-1相比较,相等,该地址不存在,不相等则继续操作。 若有希望你请追问
看了 C语言的一道题目?#incl...的网友还看了以下:
exit(EXIT_FAILURE);\if(p)*p=0;if(add_or_not==1)re 2020-05-17 …
就一句Java代码读不懂请高人帮忙解释下publicstaticintf(intn){if(n== 2020-06-12 …
(可能是很愚蠢的问题)偶数时这么写为什么有问题?if(b%2==1)returnexp(a,b-1 2020-07-23 …
C语言的一道题目?#include#include#include#includeintmain( 2020-07-23 …
return1什么意思#include<iostream.h>#include<stdlib.h> 2020-07-23 …
求教求闰年为什么写成这样求不出if(n%4==0&&n%100!=0&&n%400==0)写成这样 2020-07-24 …
说明下列函数的时间复杂度和空间复杂度(包含过程)如题说明下列函数的时间复杂度和空间复杂度(包含过程 2020-07-30 …
关于return函数f定义如下,执行语句“m=f(2);”后,m的值应为()。intf(intk){ 2020-12-15 …
Ifyouarenotsureawomanismarriedornot,itisalwayssafe 2020-12-29 …
下面代码中的“if(key[i].compare(c)==0)return1;”这句语句是什么意思s 2021-02-15 …