I used scanf in the main function to scan a character, I put the scanf in a while loop, while keyboard input it being scanned I want the other functions to operate, but I can't figure out how to get it to run properly.
Code:
//TENNIS
#include <stdio.h>
#define PRINT 0
#define GAME_A 1
#define GAME_B 2
#define DEUCE 3
#define AD_SERVER 4
#define AD_RECEIVER 5
int scoreA = 0;
int scoreB = 0;
int scoreFunct(char c);
void printFunct(int scoreA, int scoreB, char c);
int main (int argc, char **argv){
char c;
char team;
printf ("Team A or Team B serves first?: ");
scanf ("%c", &team);
printf ("Team %c to serve\n", team);
while(scanf("%c", &c) == 1){
}
return(0);
}
int scoreFunct(char c){
while((scoreA < 3) && (scoreB < 3)){
if(c == 'A'){
scoreA+=1;
}
else if (c == 'B'){
scoreB+=1;
}
else if (c == 'S'){
return(PRINT);
}
}
return(0);
}
void printFunct(int scoreA, int scoreB, char c){
if(scoreFunct(c) == PRINT){
printf("%d-%d", scoreA, scoreB);
}
}
The ones in red are what I'm stuck on, i want that function to execute while the scanf is running in the main function. I tried getchar, that gives me worse problems.
Thanks in advance