1

how can i make a simple program that prints a phrase whenever the user inputs a word. i cant seem to make what i wrote down to work. Im very new, thanks.

#include <stdio.h>
#include <stdlib.h>

int main ()
{
    char direction[20];

    printf ("where did he go? choose one option.\n");
    printf ("station, plaza, bathrooms\n");
    scanf ("%s", direction);

    printf ("%s", direction);

    if (direction == "plaza"){
        printf ("its going to be hard to find him now..");
    } else if (direction == "bathrooms"){
        printf ("lets go rush him right now!!!");
    } else if (direction == "car"){
        printf ("he must've escaped into the city!");
    }
    return (0);
}
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • 1
    What resources are you using to learn C? What do they tell you about comparing strings? If they told you that doing e.g. `direction == "plaza"` works, then you need to get new books, tutorials, or *teachers*. – Some programmer dude Sep 11 '20 at 07:28
  • You don't need two `printf` calls for two lines of data, you can break the strings up into separate quoted strings and the compiler will join them, e.g. `printf ("where did he go? choose one option.\n"` then next line `"station, plaza, bathrooms\n");` will work, or better `puts ("where did he go? choose one option.\n"` then next line `"station, plaza, bathrooms");` -- there is no conversion needed. – David C. Rankin Sep 11 '20 at 07:32
  • i'm learning by myself through youtube.. i know it works if its only one character, english isn't my main language. i have done something similar to this when i made a simple calculator that takes the operator. That's why i tried to experiment on it. – user14258852 Sep 11 '20 at 07:34
  • obviously this is not a place for new comers to learn. – user14258852 Sep 11 '20 at 07:41
  • Please take some time to read [the help pages](http://stackoverflow.com/help), especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also please take the [tour] and read about [ask] good questions. And please read [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly, this isn't a tutorial or teaching site, it's to help solve specific problems. – Some programmer dude Sep 11 '20 at 07:48

0 Answers0