#Command line utility

13 messages · Page 1 of 1 (latest)

sinful fossil
#
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
    char *operation;
    operation = argv[1];
    int num1 = atoi(argv[2]);
    int num2 = atoi(argv[3]);

    if(strcmp(operation, "+") == 0) {
        printf("%d", num1 + num2);
    }
    else if(strcmp(operation, "-") == 0) {
        printf("%d", num1 - num2);
    }
    else if(strcmp(operation, "*") == 0) {
        printf("%d", num1 * num2);
    }
    else if(strcmp(operation, "/") == 0) {
        printf("%d", num1 / num2);
    }
    return 0;
} ```

Umm, guys, I want to ask why my code is not working when I'm typing * in the command line and when changing the string name it's working properly
chrome domeBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

sullen pecan
#

"changing the string name" ?

sinful fossil
sullen pecan
#

try running your program as myprogram '*' 5 6 instead of myprogram * 5 6

#

I had to do that on my system because my shell was interpreting the * as a glob command instead of text to send to the program

sinful fossil
#

Its still not working

#

It worked for you?

sullen pecan
sinful fossil
#

It's not working for me)):

vast mist
#

Try double quotes

arctic garden
#

Might be a Windows thing