int i, diceRolls, sum;
char con ;
for(i = 0 ; i<20 ; i++)
diceRolls = (rand()%6) + 1 ;
sum += diceRolls ;
printf("Dice Rolled = %d\n", diceRolls);
printf("\nDo you want to continue?\n\n");
if(con != "yes") // the problem is here
I am having a problem with strings in an if else statement.
When i write "yes" in the program it stops the program rather than continuing the program.
Problem with Strings
Post a Reply
|Oldest Newest Rating|
· September 24, 2015
Why not just use
scanf(" %c", con);
and change your if statement like this
that way you can repeat it again and again as long as you input "y"
· September 22, 2015
you cannot use comparisons like that in c. use the strncmp function. also, by typing "yes", you are effectively overflowing the buffer and it would intentionally overflow because you used the gets function as it is insecure for writing into buffers. i very strongly suggest you use fgets instead of gets from hereon.
One of the most popular languages of all time.
|Bucky Roberts Administrator|