函数定义的有关问题。
函数定义的问题。。
请问下
这部分我想另外做个函数该怎么定义呀?新手轻喷。。。
------解决方案--------------------
------解决方案--------------------
反过来问问LZ(因为不太清楚LZ在问什么),如果我想定义一个“两个数求和”这样一个功能,函数应该怎么声明和定义?
- C/C++ code
int main(int argc, char *argv[]){ int n,j; FILE *fp; /* fp = fopen("x.log", "r"); pid_t cd; cd = fork(); if(cd < 0){ printf("fork error\n"); exit(1); }else if(cd == 0){ */ pid_t child ; int fd; /* if(argc < 3){ printf("command-line argument required\n"); return 1; } */ char ip[32]; strcpy(ip, argv[1]); if((child=fork()) < 0){ printf("fork error\n"); exit(1); }else if(child == 0){ //child fd = open("x.log", (O_RDWR|O_CREAT|O_APPEND), 0644); dup2(fd, 1); if(execlp("/usr/local/nagios/libexec/check_nrpe", "check_nrpe", "-H", ip, "-c", argv[2], NULL) < 0) printf("execlp error\n"); close(fd); } char s[100]; fp = popen("awk \'END{print}\' x.log", "r"); while(fgets(s, 99, fp)!= NULL && s[1]!= '\n') // fputs(s,stdout); ; exit(0); }
请问下
- C/C++ code
char ip[32]; strcpy(ip, argv[1]); if((child=fork()) < 0){ printf("fork error\n"); exit(1); }else if(child == 0){ //child fd = open("x.log", (O_RDWR|O_CREAT|O_APPEND), 0644); dup2(fd, 1); if(execlp("/usr/local/nagios/libexec/check_nrpe", "check_nrpe", "-H", ip, "-c", argv[2], NULL) < 0) printf("execlp error\n"); close(fd); }
这部分我想另外做个函数该怎么定义呀?新手轻喷。。。
------解决方案--------------------
------解决方案--------------------
反过来问问LZ(因为不太清楚LZ在问什么),如果我想定义一个“两个数求和”这样一个功能,函数应该怎么声明和定义?