码迷,mamicode.com
首页 > 其他好文 > 详细

popen()

时间:2014-08-22 02:46:25      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   ar   

popen()函数

bubuko.com,布布扣
 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

目标函数

bubuko.com,布布扣
 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 1024
11 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

 

popen(),布布扣,bubuko.com

popen()

标签:style   blog   http   color   os   io   for   ar   

原文地址:http://www.cnblogs.com/ben1314/p/3928471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!