samedi 18 septembre 2021

C if(var == "str") statement isn't working [duplicate]

Thank you for taking the time to read my question :D I'm trying to make a console interpreter for my new programming language (kind of like python) I type "gcc main.c" or "gcc usr/bin/main.c" (it'll be a bash terminal command like "python" or "python3")

...but, my if/else statements in c aren't working;

#include <stdio.h>

int main() {

    // VARS
    // vars here

    // CODE LEL
    printf("\n\nWelcome to the console version of Scripter.\nType `help' for a list of code.\n\n");
    while(1) {


        printf("\n\nScripter %s - Line: [%d] Lines: [%d] Variables: [Names: [%s] Values: [%d]]\n", ver, line, lines, vars, Vars);
        printf("\n Scripter >>> "); scanf("%s", code); printf("\n%s was entered.\n\n", code);
        if(code == "#") {

            line += 1; lines += 1;

        } else if(code == "<") {

            line -= 1;

        } else if(code == ">") {

            line += 1; if(line >= lines) {lines = line;}

        } else if(code == "cout-") {

            printf("Print out to the console... >>> "); scanf("%s", code);

        } else {

            printf("Error: %s is invalid (deleted.)", code);
                
            }
        }
    

}

My inputs always return as Error: (whatever I entered) is invalid (deleted.)

Does anybody know what is wrong? (gcc main.c does not show errors or warnings.)

Aucun commentaire:

Enregistrer un commentaire