缺少什么终止“性格的意思? [英] What does missing terminating " character mean?

查看:98
本文介绍了缺少什么终止“性格的意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行此程序并继续获得相同的错误。缺少终止字符是什么意思,我如何在我的代码中修复这些问题? Repl上的一切都运行正常。我复制并粘贴到Linux,现在我得到了所有这些错误。



RPS.c:162:10:警告:缺少终止字符

RPS.c:函数âprintResultsâ:

RPS.c:162:错误:缺少终止字符

RPS.c:163:错误:预期表达式之前“令牌

RPS.c :163:9:警告:缺少终止字符

RPS.c:163:错误:缺少终止字符

RPS.c:164:错误:预期â; â之前“令牌







代码:



  / *   
*描述:Rock of Game ,纸,剪刀与计算机。
*
*作者:Cole
*
*日期:10-12-2018
* /

#include < stdio.h >
#include < stdlib.h >
#include < time.h >
// 功能声明
/ * 函数名称:flushscanf
输入参数:c
描述:之后使用scanf函数。防止scanf搞乱,并使用EOF,因此在文件结束后不会读取。
返回值:void
* /

void flushScanf( void );

/ * 函数名称:compareInputs
输入参数:userInput
描述:确定用户输入是否可以运行程序。使大小写r,p,s和q可接受的输入。
返回值:结果,错误陈述或摇滚/纸/剪。
* /

int compareInputs( char );

/ * 函数名称:getInput
输入参数:userInput。
描述:为计算机和用户以及关系赢得胜利。
返回值:myWins ++,pcWins ++或tie ++。
* /

char getInput();

/ * 函数名称:printResults
输入参数:int myWins,int pcWins和int tie。
描述:打印统计的胜利和关系。
返回值:printf语句,其中包含游戏结果的正确记录。
* /

void printResults( int int int );


int main( void ){
// 变量
char userInput;
int flag = 1 ;
int myWins = 0 ;
int pcWins = 0 ;
int ties = 0 ;
int 结果;

printf( 让我们玩Rock / Paper / Scissors游戏\ n< /跨度>);

//
do {
userInput = getInput();
if (userInput == ' Q' || userInput == ' q'){
printResults(myWins, pcWins,领带);
printf( \ n谢谢你玩!);
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( 错误,请再试一次);
}

result = compareInputs(userInput);

switch (结果){
case 1
myWins ++;
break ;

case 2
pcWins ++;
break ;

case 3
tie ++;
break ;
}
} while (flag == 1 );





返回 0 ;


}
char getInput( void ) {
char userInput;
printf( \ n输入R,P,S或Q(退出):);
scanf( %c,& userInput);
flushScanf();


return userInput;
}

char check( char 输入){

}

int compareInputs( char userInput){
srand(time(NULL));

int pc =(rand()%3)+1;
// 1 = Rock
// 2 =论文
// 3 =剪刀
如果(pc == 1 & ;& userInput == ' r'){
printf( 你选择了Rock,电脑选择了Rock.\);
printf( 这是一个平局。\ n);
return 3 ;
} else if (pc == 1 && userInput == ' s'){
printf( 你选择了Scissors,电脑选择了Rock.\);
printf( Rock break Scissors,你输了!\ n);
return 2 ;
} else if (pc == 1 && userInput == ' p'){
printf( 你选择了Paper,电脑选择了Rock.\);
printf( 论文封面摇滚,你赢了!\ n);
return 1 ;
} else if (pc == 2 && userInput == ' r'){
printf( 你选择了Rock,计算机选择了Paper.\);
printf( 论文封面摇滚,你输了。\ n);
return 2 ;
} else if (pc == 2 && userInput == ' s'){
printf( 你选择了Scissors,计算机选择了Paper.\ n);
printf( 剪刀剪纸,你赢了!\ n);
return 1 ;
} else if (pc == 2 && userInput == ' p'){
printf( 你选择Paper,电脑选择Paper.\ n);
printf( 这是一个平局。\ n);
return 3 ;
} else if (pc == 3 && userInput == ' r'){
printf( 你选择了Rock,电脑选择了Scissors.\);
printf( Rock break Scissors,你赢了!\ n);
return 1 ;
} else if (pc == 3 && userInput == ' s'){
printf( 你选择了Scissors,电脑选择了Scissors.\);
printf( 这是一个领带\ n);
return 3 ;
} else if (pc == 3 && userInput == ' p'){
printf( 你选择了Paper,电脑选择了Scissors.\);
printf( 剪刀剪纸,你输了!\ n);
return 2 ;
}
return 4 ;
}

void printResults( int myWins, int pcWins, int ties){
printf( \ n你赢了%d次,计算机赢了%d次,这是一个平局%d次,myWins,pcWins,ties);
}

void flushScanf( void ){
char c = getchar();

while (c!= ' \ n'&& c!= EOF){
c = getchar();
}
}





我的尝试:



重新输入引号和其他标点符号,因为编辑器使用不同的字符系统。

解决方案

这是错误消息来自编译器,它告诉你行和错误原因。您的错误声音就像您错过了终止字符串一样。

  //  您的代码 
char * text = Hello world;

  //  正确的代码 
char * text = Hello world;

对你来说有点不同对编译器来说有很大差异;-)



提示:在多个错误上,第一个是重要的错误。它可能会触发其他人像纸牌屋。


引用:

重新输入引号和其他标点符号以防万一,因为编辑器使用不同的字符系统。

这意味着我们无法为您修复它,是原因是已经解决了这个问题。几乎可以肯定,你的一个双引号字符要么丢失了,要么你输入了一个单引号:但你显示的代码没有给出你在这里复制和粘贴时所描述的错误,所以你已经删除了这个问题! />


它确实给出了另一个错误: check 函数什么都不做,并且没有返回值。


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:

/*
    * 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.

解决方案

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.

//your code
char *text = "Hello world;

//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.


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.


这篇关于缺少什么终止“性格的意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆