得到错误:期望的标识符或'('''''''之前的标记

时间:2013-10-18 19:16:32

标签: c identifier

expected identifier or ‘(’ before ‘{’ token之前的#include之后的第一个方括号上发现此错误:int main。不知道为什么!为入门编程课程做作业。它今天到期,所以任何帮助将不胜感激!

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
{
int main(void);

int cardNum(int firstCard, int secondCard; 
int highLow;
int score;

score = 0;   
srand(time(NULL));

    printf("The current card is a %d\n" ,firstCard(2,14));
    printf("\n Will the next card be higher(1) or lower(2)? (press 0 to quit)");
    scanf("%d" ,highLow);
if cardNum > 1 && cardNum < 11
{        
     printf ("The card is: %d ,secondCard.");
}        
else if cardNum == 11
{
if highLow == 1, && secondCard > firstCard OR highLow == 2, && secondCard < firstCard
    {   
        score = score + 1; 
        printf ("\n You have guessed correctly.");
        printf ("\n Your current score is %d ,score!\n");
        printf("The current card is a ("%d" ,cardOne). \n Will the next card be           higher(1) or lower(2)? (press 0 to quit)");
    }    
else if highLow == 1, && secondCard < firstCard OR highLow == 2, && secondCard > firstCard  
    {
        score = score - 1;
        printf ("The card is: %d ,secondCard.");
        printf ("\n You have guessed incorrectly.");
        printf ("\n Your current score is %d ,score!\n");
        printf ("The current card is a %d ,cardOne."); 
        printf ("\n Will the next card be higher(1) or lower(2)? (press 0 to quit)");
    }
else if secondCard == firstCard
    {
        printf ("\n Matching cards, no change in score");
    }
else if highLow == 0
    {
        printf ("\n Thanks for playing! Your final score is %d, score.");
    }
else
    {
        printf ("\n Incorrect input. Please enter 0, 1 or 2")       
    }
}    
return(0);
}

我最初使用int main(void){但后来我得到了所有这些错误,所以我把它改成了分号,只得到了一个错误。
a3.c:在函数'main'中: a3.c:24:5:错误:预期声明说明符或'得分'之前的'...' a3.c:25:5:错误:预期声明说明符或's'之前'srand' a3.c:27:5:错误:'printf'之前的预期声明说明符或'...' a3.c:28:5:错误:'printf'之前的预期声明说明符或'...' a3.c:29:5:错误:预期声明说明符或'scanf'之前的'...' a3.c:31:5:错误:预期的声明说明符或'if'在'if'之前 a3.c:82:1:错误:预期的声明说明符或'}'在'}'标记之前 a3.c:82:1:错误:在'}'标记之前预期';',','或')' a3.c:82:1:错误:输入结束时的预期声明或声明 a3.c:82:1:警告:控制到达非空函数的末尾[-Wreturn-type]

2 个答案:

答案 0 :(得分:7)

{
int main(void);

应该是

int main(void)
{

然后我让你修复程序的下一个编译错误......

答案 1 :(得分:4)

你需要在main之后放置左大括号,而不是在它之前

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{