首页
社区
课程
招聘
未解决 [求助]命令行参数如何传递
发表于: 2019-7-11 08:59 1901

未解决 [求助]命令行参数如何传递

2019-7-11 08:59
1901
int main(int argc,char *argv[])
{
    if ( argc < 4 )
    {
        printf("usage: %s %s\n", argv[0], "-e|d infile outfile");
        exit(1);
    }
    else
    {   
        if ( (strcmp(argv[1]),"-e") )
       {
          printf("%s\n",argv[1]);
          printf("nihao.\n");
//          encoding(argv[2],argv[3]);
          exit(2);
       }
          if ( (strcmp(argv[1]),"-d") )
       {
          printf("%s\n",argv[1]);
          printf("wohao.\n");
 
//          decoding(argv[2],argv[3]);
          exit(3);  
       }
    }
}

下面的代码执行后都是打印出nihao,为啥wohao打印不出来呢?

base64 -e minase.mp3 ulg.txt
-e
nihao.

base64 -d minase.mp3 ulg.txt
-d
nihao.


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 422
活跃值: (835)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
if ( (strcmp(argv[1]),"-e") )
????
这什么鬼
2019-7-11 09:09
0
雪    币: 9626
活跃值: (1826)
能力值: ( LV5,RANK:73 )
在线值:
发帖
回帖
粉丝
3
strcmp

Return Value
The return value for each of these functions indicates the ordinal relation of string1 to string2.

Value        Relationship of string1 to string2
< 0        string1 is less than string2
0        string1 is identical to string2
> 0        string1 is greater than string2

建议楼主巩固基础
最后于 2019-7-11 09:24 被Sprite雪碧编辑 ,原因:
2019-7-11 09:24
1
雪    币: 10726
活跃值: (2730)
能力值: ( LV5,RANK:71 )
在线值:
发帖
回帖
粉丝
4
debug
2019-7-11 09:27
0
雪    币: 575
活跃值: (561)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
5
strcmp返回值了解一下
2019-7-11 09:45
1
游客
登录 | 注册 方可回帖
返回
//