#1
by こんぺいとう » 5年前
こんにちは。以下のソースコードでgccでコンパイルしたときに
highscore.c:42: error: expected ‘)’ before ‘*’ tokenという
エラーが出ます。()や,がおかしいというのは想像がつくのですが
42行目には特におかしいところが見つけられませんでした。
よろしくお願いします。
コード:
//highscore.c
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <time.h>
int getHighScore(int highScore,int score){
if(score>highScore){
return score;
}else{
return highScore;
}
}
int loadHighScore(){
FILE *fp;
int hs;
fp=fopen("highscore.txt","r");
if(fp==NULL){
printf("Failed to open file\n");
return 0;
}
fscanf(fp,"%d",&hs);
fclose(fp);
return hs;
}
void saveHighScore(int score){
FILE *fp;
fp=fopen("highscore.txt","w");
if(fp==NULL){
printf("Failed to open file\n");
return;
}
fprintf(fp,"%d",score);
fclose(fp);
}
void highScoreDisp(int highScore){
mvprintw(0,COLS/2+2,"HI SCORE:%d",highScore);
}
void getMonsterLocationU(POSITION *monster, POSITION *treasure, POSITION *unchi, int *numTreasure, int *numUnchi){
int dx=rand()%3-1;
int dy=rand()%3-1;
int origX=monster->x;
int origY=monster->y;
int diceT=rand()%10;
int diceU=rand()%3;
//移動する
if(((monster->x>0)&&(dx<0))||(((monster->x)<COLS-1)&&(dx>0))){
monster->x=monster->x+dx;
}
if(((monster->y>0)&&(dy<0))||(((monster->y)<LINES-1)&&(dy>0))){
monster->y=monster->y+dy;
}
//移動先にものがある
if((*numTreasure==1)||(*numUnchi==1)){
if((monster->x==treasure->x)&&(monster->y==treasure->y)||(monster->x==unchi->x)&&(monster->y==unchi->y)){
monster->x=origX;
monster->y=origY;
}
}
//宝を落とすかの判定
if((diceT==0)&&(*numTreasure==0)){
if((monster->x-origX!=0)&&(monster->y-origY!=0)){
treasure->x=origX;
treasure->y=origY;
*numTreasure=1;
mvprintw(treasure->y,treasure->x,"T");
}
}
//うんちを落とすかの判定
if((diceU==0)&&(*numUnchi==0)){
if((monster->x-origX!=0)&&(monster->y-origY!=0)){
unchi->x=origX;
unchi->y=origY;
*numUnchi=1;
mvprintw(treasure->y,treasure->x,"U");
}
}
int getTU(POSITION *player,POSITION *treasure,int *numTreasure,POSITION *unchi, int *numUnchi){
if(*numTreasure==1){
if((player->x==treasure->x)&&(player->y==treasure->y)){
mvprintw(treasure->y,treasure->x," ");
*numTreasure=0;
return 1;
}else{
return 0;
}
}
if(*numUnchi==1){
if((player->x==unchi->x)&&(player->y==unchi->y)){
mvprintw(unchi->y,unchi->x," ");
*numUnchi=0;
return 1;
}else{
return 0;
}
}
return 0;
}
こんにちは。以下のソースコードでgccでコンパイルしたときに
highscore.c:42: error: expected ‘)’ before ‘*’ tokenという
エラーが出ます。()や,がおかしいというのは想像がつくのですが
42行目には特におかしいところが見つけられませんでした。
よろしくお願いします。
[code]
//highscore.c
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <time.h>
int getHighScore(int highScore,int score){
if(score>highScore){
return score;
}else{
return highScore;
}
}
int loadHighScore(){
FILE *fp;
int hs;
fp=fopen("highscore.txt","r");
if(fp==NULL){
printf("Failed to open file\n");
return 0;
}
fscanf(fp,"%d",&hs);
fclose(fp);
return hs;
}
void saveHighScore(int score){
FILE *fp;
fp=fopen("highscore.txt","w");
if(fp==NULL){
printf("Failed to open file\n");
return;
}
fprintf(fp,"%d",score);
fclose(fp);
}
void highScoreDisp(int highScore){
mvprintw(0,COLS/2+2,"HI SCORE:%d",highScore);
}
void getMonsterLocationU(POSITION *monster, POSITION *treasure, POSITION *unchi, int *numTreasure, int *numUnchi){
int dx=rand()%3-1;
int dy=rand()%3-1;
int origX=monster->x;
int origY=monster->y;
int diceT=rand()%10;
int diceU=rand()%3;
//移動する
if(((monster->x>0)&&(dx<0))||(((monster->x)<COLS-1)&&(dx>0))){
monster->x=monster->x+dx;
}
if(((monster->y>0)&&(dy<0))||(((monster->y)<LINES-1)&&(dy>0))){
monster->y=monster->y+dy;
}
//移動先にものがある
if((*numTreasure==1)||(*numUnchi==1)){
if((monster->x==treasure->x)&&(monster->y==treasure->y)||(monster->x==unchi->x)&&(monster->y==unchi->y)){
monster->x=origX;
monster->y=origY;
}
}
//宝を落とすかの判定
if((diceT==0)&&(*numTreasure==0)){
if((monster->x-origX!=0)&&(monster->y-origY!=0)){
treasure->x=origX;
treasure->y=origY;
*numTreasure=1;
mvprintw(treasure->y,treasure->x,"T");
}
}
//うんちを落とすかの判定
if((diceU==0)&&(*numUnchi==0)){
if((monster->x-origX!=0)&&(monster->y-origY!=0)){
unchi->x=origX;
unchi->y=origY;
*numUnchi=1;
mvprintw(treasure->y,treasure->x,"U");
}
}
int getTU(POSITION *player,POSITION *treasure,int *numTreasure,POSITION *unchi, int *numUnchi){
if(*numTreasure==1){
if((player->x==treasure->x)&&(player->y==treasure->y)){
mvprintw(treasure->y,treasure->x," ");
*numTreasure=0;
return 1;
}else{
return 0;
}
}
if(*numUnchi==1){
if((player->x==unchi->x)&&(player->y==unchi->y)){
mvprintw(unchi->y,unchi->x," ");
*numUnchi=0;
return 1;
}else{
return 0;
}
}
return 0;
}
[/code]