Using argv in C?

前端 未结 6 1360
难免孤独
难免孤独 2020-12-03 22:37

For an assignment, I am required to have command line arguments for my C program. I\'ve used argc/argv before (in C++) without trouble, but I\'m unsure if C style strings ar

6条回答
  •  被撕碎了的回忆
    2020-12-03 22:49

    You can't use == to compare strings like that in C. That's just comparing the addresses of argv[1] and your literal, which are pretty much guaranteed to be different.

    Use strcmp instead. eg:

    if (!strcmp("-e", argv[1])) {
    

提交回复
热议问题