Hello all,
I am relatively new to programming and ave encountered a problem in a simple text base RPG I am writing. The program compiles without error however the program does not function as I intended. I am running Windows 7 64-Bit using Pelles C to compile my code.
#include <stdio.h>
int main(void)
{
printf("MRPG - My Role Playing Game");
printf("\n\n\nYou are in a desert wasteland, with the sound of harsh winds rushing past your ears\n What shall you do?\n");
char a;
scanf ("%s", & a);
if ("walk" == "%s", & a)
{
printf("You decide to walk, you walk for 3 miles until you feint in the devastating heat.");
}
elseif ("shout" == "%s", & a)
{
printf("You call for help with all of your effort, but after half an hour the eerie silence of the sandy desert only heightens the doubt, rising from your stomach");
}
else
{
printf("You cannot do that right now ,try walking");
}
}
The problem i have encountered is that the initial if statement (if ("walk" == "%s", & a)) is run no mater what I input into the scanf.
So if I were to type in "help", "printf("You decide to walk, you...") " is the function carried out by the system.
I just want the user to get one result when typing one thing, and another result when typing anything else.
I apologize if the solution to my dilemma is simple, I have little experience in C programming.
#include <stdio.h>
int main(void)
{
printf("TRPG - Tyler's Role Playing Game");
printf("\n\n\nYou are in a desert wasteland, with the sound of Tony's grunt booming around you\n What shall you do?\n");
char a;
scanf ("%s", & a);
if (strcmp("walk",a) == 0)
{
printf("You decide to walk, you walk for 3 miles until you notice a damp sensation in your shoes. You take off your left shoe, to discover a blood stained sock.");
}
elseif (strcmp("shout",a) == 0)
{
printf("You call for help with all of your effort, but after half an hour the eerie silence of the sandy desert only heightens the doubt, rising from your stomach");
}
else
{
printf("You cannot do that right now ,try walking");
}
}
Now when i enter text into the console the program ends, and doesn't run any functions.
What have i done wrong?