Ok.. so i have that code and i cant get the Do While statement right…
#include <stdio.h>
#include <stdlib.h>
int main ()
{
int nWinsPC, nWinsPlayer;
char cChoose[1];
do {
system("cls");
printf("Vamos jogar um jogo?\n");
printf("-\n");
printf("Escolha (p)edra, p(a)pel ou (t)esoura: ");
getchar();
scanf("%1[^\n]", cChoose);
} while(cChoose != "p");
system("pause");
}
That system should be that easy… the CHOOSE SCREEN stays in loop while Player doesnt type “p”, but i can’t get this working…
🙁
thanks in advance
EDIT
Problem solved:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int nWinsPC, nWinsPlayer;
char cChoose[2];
do {
system("cls");
printf("Vamos jogar um jogo?\n");
printf("-\n");
printf("Escolha (p)edra, p(a)pel ou (t)esoura: ");
scanf("%s", cChoose);
} while ( strcmp(cChoose,"p") );
system("pause");
}
The statement :
must be used which returns zero if two strings are equal.
Moreover, if you are using cChoose as a string you must use two characters as the length of cChoose because string is always terminated by a null character – ‘\0’. So, use :
EDIT:
The getchar() before the scanf() takes the initial ‘p’, thus nothing happens first time. Whereas the second time, the getchar() first recieves the ‘\n’ left in the first line and scanf reads the “p” properly.
Remove the getchar() and your code would work fine.