首页 > 代码库 > 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 }
View Code

目标函数

 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 }
View Code