Click here to Skip to main content
15,867,291 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am trying to run this program and keep getting the same errors. What does missing terminating character mean and how can I fix these issues in my code? Everything runs fine on Repl for me. I copied and pasted to Linux and now I got all of these errors.

RPS.c:162:10: warning: missing terminating " character
RPS.c: In function âprintResultsâ:
RPS.c:162: error: missing terminating " character
RPS.c:163: error: expected expression before â%â token
RPS.c:163:9: warning: missing terminating " character
RPS.c:163: error: missing terminating " character
RPS.c:164: error: expected â;â before â}â token



code:

C++
/*
    * Description: Game of Rock, Paper, Scissors with the Computer.
    *
    * Author: Cole 
    *
    * Date: 10-12-2018
    */
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    //FUNCTION DECLARATIONS
    /*Function Name: flushscanf
    Input Parameters: c
    Description: Used after scanf. Prevents scanf from messing up, and EOF is used so it isn't read after the end of the file.
    Return Values: void
    */
    void flushScanf(void);
    
    /*Function name: compareInputs
    Input parameters: userInput
    Description: Determines whether user input is acceptable to run the program. Makes upper and lower case r, p, s, and q acceptable inputs.
    Return Values: Results, error statement, or rock/paper/scissors.
    */
    int compareInputs(char);
    
    /*Function name: getInput
    Input parameters: The userInput.
    Description: Tallies the wins for the computer and user, as well as the ties.
    Return Values: myWins++, pcWins++, or ties++.
    */
    char getInput();
    
    /*Function name: printResults
    Input parameters: int myWins, int pcWins, and int ties.
    Description: Prints the tallied wins and ties.
    Return Values: printf statement with correct record of results from games played.
    */
    void printResults(int, int, int);
    
    
    int main(void) {
    //variables
    char userInput;
    int flag=1;
    int myWins= 0;
    int pcWins= 0;
    int ties= 0;
    int result;
    
    printf("Let’s play a game of Rock/Paper/Scissors \n");
    
    //
    do{
      userInput = getInput();
      if(userInput == 'Q' || userInput == 'q') {
        printResults(myWins, pcWins, ties);
        printf("\nThank you for playing!");
        flag =0;
        }else if(userInput == 'R' || userInput == 'r'){
        userInput = 'r';
        }else if(userInput == 'P' || userInput == 'p'){
        userInput = 'p';
        }else if(userInput == 'S' || userInput == 's'){
        userInput = 's';
        }else{
          printf("Error, Please try again\n ");
        }
    
        result = compareInputs(userInput);
    
        switch(result){
          case 1:
            myWins++;
            break;
    
            case 2:
            pcWins++;
            break;
    
            case 3:
            ties++;
            break;
        }
    }while(flag==1);
    
    
    
    
    
      return 0;
    
      
    }
    char getInput(void){
      char userInput;
      printf("\nEnter R, P, S, or Q (for quit):");
      scanf("%c", &userInput);
      flushScanf();
    
     
      return userInput;
    }
    
    char check(char input){
    
    }
    
    int compareInputs(char userInput){
    srand(time(NULL));
    
    int pc = (rand()%3)+1;
    // 1 = Rock
    // 2 = Paper
    // 3 = Scissors
    if (pc==1 && userInput == 'r'){
      printf("You picked Rock, the computer picked Rock.\n");
      printf("It's a tie.\n");
      return 3;
    } else if(pc==1 && userInput == 's'){
      printf("You picked Scissors, the computer picked Rock.\n");
      printf("Rock breaks Scissors, you lose!\n");
      return 2;
      }else if(pc==1 && userInput == 'p'){
        printf("You picked Paper, the computer picked Rock.\n");
        printf("Paper covers rock, you win!\n");
        return 1;
      }else if (pc==2 && userInput == 'r'){
        printf("You picked Rock, the computer picked Paper.\n");
        printf("Paper covers rock, you lose.\n");
        return 2;
      } else if (pc==2 && userInput == 's'){
        printf("You picked Scissors, the computer picked Paper.\n");
        printf("Scissors cuts Paper, you win!\n");
        return 1;
      } else if (pc==2 && userInput == 'p'){
        printf("You picked Paper, the computer picked Paper.\n");
        printf("It's a tie.\n");
        return 3;
      } else if (pc==3 && userInput == 'r') {
        printf("You picked Rock, the computer picked Scissors.\n");
        printf("Rock breaks Scissors, you win!\n");
        return 1;
      } else if (pc==3 && userInput =='s'){
        printf("You picked Scissors, the computer picked Scissors.\n");
        printf("It's a tie\n");
        return 3;
      }  else if (pc==3 && userInput == 'p'){
      printf("You picked Paper, the computer picked Scissors.\n");
      printf("Scissors cuts paper, You lose!\n");
      return 2;
      }
      return 4;
    }
    
    void printResults(int myWins, int pcWins, int ties){
      printf("\nYou won %d times, the computer won %d times, and it was a tie %d times", myWins, pcWins, ties);
    }
    
    void flushScanf(void) {
      char c = getchar();
    
      while (c != '\n' && c != EOF) {
        c = getchar();
        }
      }


What I have tried:

Retyped quotations and other punctuation marks in case its because the editor uses a different character system.
Posted
Updated 1-May-23 2:24am
v2
Comments
Rick York 13-Oct-18 13:33pm    
Have a look at the functions tolower and toupper. They convert a character to the case you want so then you don't have to test for both of them and that can simplify your code.

This are error messages from the compiler which tells you the line and the error cause. You error sound like you have miss to terminate a string.
C++
//your code
char *text = "Hello world;
C++
//correct code
char *text = "Hello world";
A slight difference for you but a big difference for the compiler ;-)

tip: on multiple errors the first is the important error. It may trigger the others like a house of cards.
 
Share this answer
 
v2
Comments
CPallini 13-Oct-18 6:53am    
In fact
const char * text = "Hello world";

would have been the correct code. :-D
My 5.
Quote:
Retyped quotations and other punctuation marks in case its because the editor uses a different character system.
And that means we can't fix it for you, because that has removed the problem. Almost certainly, one of your double quote characters is either missing, or you have typed a single quote instead: but the code you show does not give the error you describe when copied and pasted here, so you have already removed the problem!

It does give another error though: the check function does nothing, and does not return a value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900