标签:style blog http color os io for ar
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 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 }
标签:style blog http color os io for ar
原文地址:http://www.cnblogs.com/ben1314/p/3928471.html