[习题8]if 、else if 、else、布尔运算符(+在线

2018-09-12  本文已影响1人  AkuRinbu

使用教材

《“笨办法” 学C语言(Learn C The Hard Way)》
https://www.jianshu.com/p/b0631208a794

Makefile

CC=clang
CFLAGS=-Wall -g

clean:
    rm -f ex8

https://www.jianshu.com/p/f7e190e9f4c5

ex8.c

#include <stdio.h>

int main(int argc, char *argv[])
{
    int i = 0;

    if(argc == 1) {
        printf("You only have one argument. You suck.\n");
    } else if(argc > 1 && argc < 4) {
        printf("Here's your arguments:\n");

        for(i = 0; i < argc;i++) {
            printf("%s\n", argv[i]);
        }
        printf("\n");
    } else {
        printf("You have too many arguments. You suck.\n");
    }

    return 0;
}

Run

anno@anno-m:~/Documents/mycode/ex8$ make ex8
clang -Wall -g    ex8.c   -o ex8

anno@anno-m:~/Documents/mycode/ex8$ ./ex8
You only have one argument. You suck.

anno@anno-m:~/Documents/mycode/ex8$ ./ex8 one
Here's your arguments:
./ex8
one

anno@anno-m:~/Documents/mycode/ex8$ ./ex8 one two
Here's your arguments:
./ex8
one
two

anno@anno-m:~/Documents/mycode/ex8$ ./ex8 one two three
You have too many arguments. You suck.

参考资料

https://en.cppreference.com/w/c/language/expressions

C C language Expressions

https://en.cppreference.com/w/c/language/expressions

C C language Expressions
用网页提供在线编辑器、编译器 run一下想测试的代码

https://coliru.stacked-crooked.com/
1、默认的命令是:
g++ -std=c++17 -O2 -Wall -pedantic -pthread main.cpp && ./a.out
2、可以加上自己的参数,写成:
clang -Wall -g main.cpp && ./a.out one two
3、点击 Compile,link and run

在线编译器 coliru
上一篇 下一篇

猜你喜欢

热点阅读