- 论坛徽章:
- 0
|
#include<stdlib.h>
#include<asm/io.h>
#include<unistd.h>
#include<stdio.h>
#include<string.h>
main()
{ char buf[80];
char pid[6];
FILE *p,*q;
char path[80]="/home/span/execbin/Log/BtsProxyStd.";
char *b=NULL;
char string[10]=".dbg";
int flag=0,i=0,k=0,j=0;
if((p= fopen( "tmp", "w+" ))==NULL)
perror("open file tmp error");
system("ps -ef|grep btsProxy >>tmp");
printf("I\n");
if((b=fgets(buf,80,p))==NULL)
{perror("Copy char from file to mem error ");
exit(0);}
printf("IV\n");
do
{if ((strstr(buf,"./btsProxy"))!=NULL)
{printf("%s",buf);
b=strtok(buf," ");
printf("%s\n",b);
b=strtok(NULL," ");
printf("%s\n",b);
strncpy(pid,b,strlen(b));
printf("%s\n",pid);
sprintf(path,"%s%s%s",path,pid,string);
// strcat(path,pid);
// printf("%s\n",path);
// strcat(path,string);
printf("%s\n",path);
flag=1;
}
printf("V\n");
if(b==NULL)
printf("#\t");
if(flag==1)
printf("$\t");
}while((b=fgets(buf,80,p))!=NULL&&flag==0);
//fclose(p);
system("rm -fr tmp");
printf("\n%s",path);
//q=fopen(path,"r");
if((q = fopen(path, "r" ))==NULL)
{ perror("open file BscStd.*.dbg error");
exit(0);
}
if((b=fgets(buf,80,q))==NULL)
{perror("Copy char from file to mem error ");
exit(0);}
printf("ok!\n");
do
{printf("III\n");
if((b=strstr(buf,"Active Call"))!=NULL)
{printf("%s",buf);
k=0;
j=0;
while(*b!='\0'&&j<10)
{
if('9'>*buf&&*buf>'0')
{i=*b-'0';
k=k*10+i;
printf("%d",k);
}
b++;
j++;
}
}
}while((b=fgets(buf,80,q))!=NULL);
printf("return");
return k;
}
我程序中拼接成的path 路径,没问题,该路径下有文件.就是打不开.
我给path 驸常量值,能打开文件.
为什么啊.
高手指点一下啊. |
|