No compiler errors, but there is a bug somewhere

Wednesday, July 2, 2014

I compiled with "gcc -ansi -pedantic -W -Wall -o ". I only get 2 errors when I compile, and here they are:



easter_eggs.c: In function ‘main’:
easter_eggs.c:23:18: warning: multi-character character constant [-Wmultichar]
if (prompt == 'egg1')
^
easter_eggs.c:23:4: warning: comparison is always false due to limited range of data type [-Wtype-limits]
if (prompt == 'egg1')


when I run the program and hit S, it displays the top 2 printf statements 2 times each. If I type anything and press enter nothing happens it just goes back to the prompt. Even if I type egg1, it still goes back to prompt. Here is the source:



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

int main()
{
char first_option;
char prompt;

system("clear");
system("toilet -f future -F gay Easter Eggs");
printf("\nFind all the easter eggs and you win. Simple enough.\n");
printf("Hit S to start and Q to quit\n");
scanf("%c", &first_option);

if (first_option == 's')
{
while (1)
{
printf("To exit hit Ctrl + C\n");
printf("You must find all easter eggs simply by typing stuff in the prompt below: \n");
scanf(">%c", &prompt);
getchar();
if (prompt == 'egg1')
{
printf("Found 1\n");
}
}
}

if (first_option == 'q')
{
exit(0);
}

else
{
printf("Invalid input. Press Enter to continue\n");
getchar();
main();
}

return 0;
}






http://ift.tt/1qp2XaX