首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

argv的用法, 错在哪里

2012-03-04 
argv的用法, 请高手看看错在哪里/*hello_to.c*/#includestdio.hintmain(intargc,char*argv[]){inti,jin

argv的用法, 请高手看看错在哪里
/*     hello_to.c     */

#include   <stdio.h>

int   main(int   argc,   char   *argv[])
{
      int   i,j;
      int   index;
      char   name[100];

      index   =   0;
      for(i   =   1;   i <3;   i++){
            for(j   =   0;   argv[i][j]   !=   '\0 ';   j++)
                    name[index++]   =   argv[i][j];
            if(i   ==2)
                  name[index]   =   '\0 ';
            else
                  name[index++]   =   ' ';
          }
    printf( "Hello,   %s.\n ",   name);
 
    return   0;
}

运行结果:
          $./hello_to     Michele
error.....
如果   $./hello_to     Michele   Lee
输出       Hello,   Michele   Lee.

我想要输入     $./hello_to     Michele   也能正常运行,   输出       Hello,   Michele   该怎么改??



[解决办法]
for(i = 1; i <3; i++)
===>
for(i = 1; i <argc; i++)

热点排行