怎么会这样 帮忙看看!
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>
char * al(char *);
int main (int argc,char * argv[])
{
printf("%s \n",al("www.baidu.com"));
return 0;
}
char * al(char * www)
{
char buffer[100];
char *ip=(char *)malloc(sizeof(char) * 15);
memset(buffer,0,sizeof(buffer));
sprintf(buffer,"ping %s",www);
FILE * fp=popen(buffer,"r");
memset(buffer,0,sizeof(buffer));
fgets(buffer,sizeof(buffer),fp);
ip = strtok(buffer,")");
ip = strtok(ip,"(");
ip = strtok(NULL,"(");
printf(ip); //不加这个printf 输出见【a】 加上这个语句就正常 见【b】
return ip;
}
~
结果:
[@localhost ~]$ cd Templates/
[@localhost Templates]$ gcc 2.c -o 2.out
[@localhost Templates]$ ./2.out
[a]输出:
[@localhost Templates]$ gcc 2.c -o 2.out
[@localhost Templates]$ ./2.out
[b]输出:180.97.33.107180.97.33.107
[@localhost Templates]$
哪位帮忙看看
[ 本帖最后由 glarm 于 2015-9-17 10:08 编辑 ]