Chinaunix首页 | 论坛 | 博客
  • 博客访问: 532766
  • 博文数量: 150
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 1861
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-17 00:19
文章分类

全部博文(150)

文章存档

2011年(1)

2009年(14)

2008年(135)

我的朋友

分类: LINUX

2008-09-27 11:00:01

导制错误的代码:



void parse( char* message )
{
  char *pch;
  int counter=0;
  int i;
  //char *message1="hello-world";

  printf( "can parse\n" );
  pch = strtok( message,",*,\n");
  while( pch != NULL ){
  
    printf( "counter:%d---%s\n", counter ,pch);
    pch= strtok( NULL ,",*\n");

 strcpy( save_info[counter], pch );//这儿错误,如果此时pch为NULL,则出错
    counter++;
  }
// printf( "the last counter is %d\n",counter );
正常:

  for( i=0; i<counter;i++){
    printf("save_info[%d]:%s\n",i,save_info[i]);
  }


正常:






void parse( char* message )
{
  char *pch;
  int counter=0;
  int i;
  //char *message1="hello-world";

  printf( "can parse\n" );
  pch = strtok( message,",*,\n");
  while( pch != NULL ){
    strcpy( save_info[counter], pch );
    printf( "counter:%d---%s\n", counter ,pch);
    pch= strtok( NULL ,",*\n");
    counter++;
  }
// printf( "the last counter is %d\n",counter );

  for( i=0; i<counter;i++){
    printf("save_info[%d]:%s\n",i,save_info[i]);
  }

阅读(916) | 评论(0) | 转发(0) |
0

上一篇:strtok ()core dump

下一篇:我的代码质量

给主人留下些什么吧!~~