请问error C2059: syntax error : '}' 这个错误怎么解决?
本帖最后由 zorodream 于 2016-9-7 19:36 编辑#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <stdlib.h>
#define BELL '\a'
#define DEALER 0
#define PLAYER 1
#define ACELOW 0
#define ACEHIGH 1
int askedForName = 0;
void dispTitle(void);
void initCardsScreen(int cards,
int playerPoints,
int dealerPoints,
int total,
int * numCards);
int dealCard(int *numCards,int cards);
void dispCard(int cardDrawn,int points);
void totalIt(int points,int total,int who);
void dealerGetsCard(int *numCards,int cards,int dealerPoints);
void playersGetsCard(int *numCards,int cards,int playerPoints);
char getAns(char mesg[]);
void findWinner(int total);
main ()
{
int numCards;
int cards,playerPoints,dealerPoints,total;
char ans;
do
{
initCardsScreen(cards,
playerPoints,
dealerPoints,
total,
&numCards);
dealerGetsCard (&numCards,cards,dealerPoints);
printf("\n");
playersGetsCard(&numCards,cards,playerPoints);
playersGetsCard(&numCards,cards,playerPoints);
do
{
ans = getAns("Hit or stand(H/S)?");
if (ans == 'H')
{
playersGetsCard(&numCards,cards,playerPoints);
}
}while (ans != 'S');
totalIt(playerPoints,total,PLAYER);
do
{
dealerGetsCard (&numCards,cards,dealerPoints);
}
while (dealerPoints<17);
totalIt(dealerPoints,total,DEALER);
findwinner(total);
ans = getAns("\nPlay again (Y/N) ? ");
}
while (ans == 'Y');
return ;
}
void initCardsScreen(int cards,
int playerPoints,
int dealerPoints,
int total,
int *numCards);
{
int sub,val = 1;
char firstName;
*numCards = 52;
for (sub = 0; sub <= 51; sub++)
{
val = (val == 14) ? 1 : val;
cards = val;
val++;
}
for (sub = 0; sub <= 1; sub++)
{
playerPoints = dealerPoints = total = 0;
}
dispTitle();
if (askedForName == 0)
{
printf("\nWhat is your first name?");
scanf("%s",firstName);
askedForName = 1;
printf("OK, %s, get ready for casino action!\n\n",firstName);
getchar();
}
return;
}
/*这个功能给玩家一张牌并更新玩家的点数*/
void playersGetsCard(int *numCards,int cards,int playerPoints);
{
int newCard;
newCard = dealCard(numCards,cards);
printf("You draw : ");
dispCard(newCard,playerPoints);
}
/*这个功能给dealer一张牌并更新dealer的点数*/
void dealerGetsCard(int *numCards,int cards,int dealerPoints);
{
int newCard;
newCard = dealCard(numCards,cards);
printf("The dealer draws : ");
dispCard(newCard,playerPoints);
}
/*这个功能从桌上得到一张牌并且把它存在庄家或者玩家的分数中*/
int dealCard(int *numCards,int cards);
{
int cardDrawn,subDraw;
time_t t;
srand(time(&t));
subDraw = ( rand() % (*numCards));
cardDrawn = cards;
cards = cards[*numCards-1];
(*numCards)-;
return cardDrawn;
}
/*展示最后发出的牌并且更新点数*/
void dispCard(int cardDrawn,int points);
{
switch (cardDrawn)
{
case(11): printf("%s\n,"Jack");
points += 10;
points += 10;
braeak;
case(12): printf("%s\n,"Queen");
points += 10;
points += 10;
braeak;
case(13): printf("%s\n,"King");
points += 10;
points += 10;
braeak;
default : points += cardDrawn;
if (cardDrawn == 1)
{
printf("%s\n,"ACE");
points += 11;
}
else
{
points += cardDrawn;
printf("%D\n",cardDrawn);
}
}
return ;
}
/*计算出玩家或者庄家的总点数,并判断谁是赢家。考虑到 A 是1或者11.*/
void totalIt(int points,int total,int who);
{
if ((points == points) || (points > 21))
{
total = points;
}
else
{
total = points;
}
if (who ==PLAYER)
{
printf("You have a total of %d\n\n",total);
}
else
{
printf("The house stands with a total of %d\n\n",total);
}
return ;
}
/*打印出赢家*/
void findWinner(int total);
{
if (total == 21)
{
printf("The house wins.\n");
return ;
}
if (total > 21) && (total > 21)
{
printf("%s","Nobody wins.\n");
return ;
}
if (total >= total) && (total < 21)
{
printf("The house wins.\n");
return ;
}
printf("%s%c","You win!\n");
return ;
}
/*21*/
char getAns(char mesg[]);
{
char ans;
printf("%s",mesg);
ans = getchar();
getchar();
return toupper(ans);
}/*错误指向这一行*/
/*清除屏幕*/
void dispTitle(void)
{
int i = 0;
while (i < 25)
{
printf("\n");
i++;
}
printf("\n\n*Step right up to the Blackjack tables*\n\n");
return ;
}
大家好,这个代码有点长,我打了一个上午。。。是一个关于21点小游戏的代码,最后运行的时候提示的错误是
error C2059: syntax error : '}'
执行 cl.exe 时出错.
但是我重新打了一遍{},都没有解决,请大家帮我上机运行一下,看看到底是哪里错了
真的很谢谢了,不能上机的如果眼睛能看出来就真是太厉害了!!
char getAns(char mesg[]);//……错误指向这一行
{
char ans;
printf("%s",mesg);
ans = getchar();
getchar();
return toupper(ans);
}/*错误指向这一行*/{:9_237:} 楼上正解,220行明显多了个逗号 调试呗,一步步执行一定可以找出错误{:10_281:} 可是 还是没有解决啊... 啊啊啊啊,呼叫版主,我手抖的点了”已经解决”啊~~~~~~~
并没有解决···
咋办
跪求!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 本帖最后由 mingcxx 于 2016-9-7 21:20 编辑
再看看。。。
mingcxx 发表于 2016-9-7 21:05
主要是多处的语法错误,修正以后剩下一个未定义标识符playerPoints(做了注释),你看看能改不:
你好,首先感谢你的耐心和指导!
在代码的第15行不是定义了playerPoints吗?是一个数组。
还有,这个程序是一个21点的小游戏。是看的一本外国的教材。这个程序是书后附录的一个代码程序。
Greg Perry写的
不过话说,还是国内的教材扎实点,这老外写的我感觉太浅了。图画多于字。
再次感谢! mingcxx 发表于 2016-9-7 21:05
再看看。。。
多谢你的耐心~
再次感谢 zorodream 发表于 2016-9-7 21:25
多谢你的耐心~
再次感谢
改完了,主要是多处的语法错误。最后剩下俩,我不太明白,就没改:函数findwinner()未定义和变量playerPoints未定义,做了注释,你看一下能改不:#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <stdlib.h>
#define BELL '\a'
#define DEALER 0
#define PLAYER 1
#define ACELOW 0
#define ACEHIGH 1
int askedForName = 0;
void dispTitle(void);
void initCardsScreen(int cards,
int playerPoints,
int dealerPoints,
int total,
int * numCards);
int dealCard(int *numCards, int cards);
void dispCard(int cardDrawn, int points);
void totalIt(int points, int total, int who);
void dealerGetsCard(int *numCards, int cards, int dealerPoints);
void playersGetsCard(int *numCards, int cards, int playerPoints);
char getAns(char mesg[]);
void findWinner(int total);
int main(void)
{
int numCards;
int cards, playerPoints, dealerPoints, total;
char ans;
do
{
initCardsScreen(cards,
playerPoints,
dealerPoints,
total,
&numCards);
dealerGetsCard(&numCards, cards, dealerPoints);
printf("\n");
playersGetsCard(&numCards, cards, playerPoints);
playersGetsCard(&numCards, cards, playerPoints);
do
{
ans = getAns("Hit or stand(H/S)?");
if (ans == 'H')
{
playersGetsCard(&numCards, cards, playerPoints);
}
} while (ans != 'S');
totalIt(playerPoints, total, PLAYER);
do
{
dealerGetsCard(&numCards, cards, dealerPoints);
} while (dealerPoints<17);
totalIt(dealerPoints, total, DEALER);
findwinner(total); //函数findwinner()未定义
ans = getAns("\nPlay again (Y/N) ? ");
} while (ans == 'Y');
return 0;
}
void initCardsScreen(int cards, int playerPoints, int dealerPoints, int total, int *numCards)
{
int sub, val = 1;
char firstName;
*numCards = 52;
for (sub = 0; sub <= 51; sub++)
{
val = (val == 14) ? 1 : val;
cards = val;
val++;
}
for (sub = 0; sub <= 1; sub++)
{
playerPoints = dealerPoints = total = 0;
}
dispTitle();
if (askedForName == 0)
{
printf("\nWhat is your first name?");
scanf("%s", firstName);
askedForName = 1;
printf("OK, %s, get ready for casino action!\n\n", firstName);
getchar();
}
return;
}
/*这个功能给玩家一张牌并更新玩家的点数*/
void playersGetsCard(int *numCards, int cards, int playerPoints)
{
int newCard;
newCard = dealCard(numCards, cards);
printf("You draw : ");
dispCard(newCard, playerPoints);
}
/*这个功能给dealer一张牌并更新dealer的点数*/
void dealerGetsCard(int *numCards, int cards, int dealerPoints)
{
int newCard;
newCard = dealCard(numCards, cards);
printf("The dealer draws : ");
dispCard(newCard, playerPoints); //playerPoints未定义,且playerPoints类型错误,如果有playerPoints,应该写&playerPoints
}
/*这个功能从桌上得到一张牌并且把它存在庄家或者玩家的分数中*/
int dealCard(int *numCards, int cards)
{
int cardDrawn, subDraw;
time_t t;
srand((unsigned int)time(&t));
subDraw = (rand() % (*numCards));
cardDrawn = cards;
cards = cards[*numCards - 1];
(*numCards)--;
return cardDrawn;
}
/*展示最后发出的牌并且更新点数*/
void dispCard(int cardDrawn, int points)
{
switch (cardDrawn)
{
case(11) : printf("%s\n","Jack");
points += 10;
points += 10;
break;
case(12) : printf("%s\n","Queen");
points += 10;
points += 10;
break;
case(13) : printf("%s\n","King");
points += 10;
points += 10;
break;
default:
points += cardDrawn;
if (cardDrawn == 1)
{
printf("%s\n","ACE");
points += 11;
}
else
{
points += cardDrawn;
printf("%D\n", cardDrawn);
}
}
return;
}
/*计算出玩家或者庄家的总点数,并判断谁是赢家。考虑到 A 是1或者11.*/
void totalIt(int points, int total, int who)
{
if ((points == points) || (points > 21))
{
total = points;
}
else
{
total = points;
}
if (who == PLAYER)
{
printf("You have a total of %d\n\n", total);
}
else
{
printf("The house stands with a total of %d\n\n", total);
}
return;
}
/*打印出赢家*/
void findWinner(int total)
{
if (total == 21)
{
printf("The house wins.\n");
return;
}
if (total > 21 && total > 21)
{
printf("%s", "Nobody wins.\n");
return;
}
if (total >= total && total < 21)
{
printf("The house wins.\n");
return;
}
printf("%s%c", "You win!\n");
return;
}
/*21*/
char getAns(char mesg[])
{
char ans;
printf("%s", mesg);
ans = getchar();
getchar();
return toupper(ans);
}/*错误指向这一行*/
/*清除屏幕*/
void dispTitle(void)
{
int i = 0;
while (i < 25)
{
printf("\n");
i++;
}
printf("\n\n*Step right up to the Blackjack tables*\n\n");
return;
} zorodream 发表于 2016-9-7 21:24
你好,首先感谢你的耐心和指导!
在代码的第15行不是定义了playerPoints吗?是一个数组。
还有,这个 ...
那不是一个函数原型的声明吗:void initCardsScreen(...) mingcxx 发表于 2016-9-7 21:33
改完了,主要是多处的语法错误。最后剩下俩,我不太明白,就没改:函数findwinner()未定义和变量playerPo ...
谢谢真的很谢谢
可以成功运行了,不过运行的结果和想象的有差别,应该是源码的问题
真的再次感谢!~~~
看来出现error C2059: syntax error : '}' 这个错误一般是有语法错误呢
谢谢你~~~
页:
[1]