免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1952 | 回复: 3
打印 上一主题 下一主题

大虾求救c/C++编程. [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-16 17:46 |只看该作者 |倒序浏览
#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 驸常量值,能打开文件.
为什么啊.
高手指点一下啊.

论坛徽章:
0
2 [报告]
发表于 2007-05-16 21:23 |只看该作者
BtsProxyStd. 多了一个点吧

论坛徽章:
0
3 [报告]
发表于 2007-05-21 15:40 |只看该作者

回复 #1 truelove120 的帖子

文件名前面要多一个点,不然不行

论坛徽章:
0
4 [报告]
发表于 2007-05-21 19:12 |只看该作者
你这样打印你的path路径看看是什么:
printf(“path=%s##\n”,path)l
看看你path后面是否存在空格。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP