首页 > 代码库 > popen()
popen()
popen()函数
1 /*============================================ 2 > Copyright (C) 2014 All rights reserved. 3 > FileName:my_ponen.c 4 > author:donald 5 > details: 6 ==============================================*/ 7 #include <unistd.h> 8 #include <stdio.h> 9 #include <stdlib.h>10 #include <string.h>11 int main(int argc, const char *argv[])12 {13 int left,right,sum;14 FILE* fp ;15 char cmd[1024] = "";16 while(1){17 scanf("%d%d",&left,&right);18 sprintf(cmd,"%s %d %d",argv[1],left,right);19 fp = popen(cmd,"r");20 fscanf(fp,"%d",&sum);21 printf("result is : %d\n",sum);22 23 pclose(fp);24 }25 return 0;26 }
目标函数
1 /*============================================ 2 > Copyright (C) 2014 All rights reserved. 3 > FileName:mystring.c 4 > author:donald 5 > details: 6 ==============================================*/ 7 #include <stdio.h> 8 #include <stdlib.h> 9 #include <string.h>10 #define N 102411 int main(int argc, const char *argv[])12 {13 int index;14 char buf[N];15 memset(buf,0,N);16 for(index = argc - 1;index > 0;index --){17 strcat(buf,argv[index]);18 strcat(buf," ");19 }20 printf("%s\n",buf);21 return 0;22 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。