Using argv in C?

前端 未结 6 1359
难免孤独
难免孤独 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:50

    The line

    if(argv[1]=="-e"){
    

    compares pointers, not strings. Use the strcmp function instead:

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

提交回复
热议问题