我有一个名为 character_game 的函数,它应该在 main() 中使用两个参数调用,即正确的字符答案和尝试次数。当我尝试编译它时,它显示:utilities.c:133:1: error: expected declaration or statement at end of input,其中 133:1 是包含函数右括号的代码的最后。
这是代码,我无法弄清楚它有什么问题,我的助教也无法弄清楚。
这是包含其他功能的整个实用程序.c 代码。
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "utilities.h"
int random_value(int lower_limit, int upper_limit);
void draw_square(int size, char ch){
int row, col = 0;
for(row = 0; row < size; row++){
for(col = 0; col < size; col++){
printf("%c",ch);
}
printf("\n");
}
}
void draw_triangle(int size, char ch){
int row;
int spaces_to_print;
int stars_to_print=1;
int previous_stars;
for (row == 1; row < size; row++){
previous_stars = stars_to_print;
spaces_to_print = size-row;
while (spaces_to_print > 0){
printf(" ");
spaces_to_print--;
}
while (stars_to_print > 0){
printf("%c", ch);
stars_to_print--;
}
if (stars_to_print == 0){
printf("\n");
stars_to_print = previous_stars+2;
}
}
}
int number_game(int correct_answer, int max_guesses){
int guessed_num;
do{
printf("num?");
scanf("%d", &guessed_num);
if (guessed_num > correct_answer){
printf("too high\n");
}
if (guessed_num < correct_answer){
printf("too low\n");
}
if (guessed_num == correct_answer){
return 1;
}
max_guesses--;
printf("max guesses now: %d\n", max_guesses);
}while (max_guesses > 0);
return 0;
int character_game(char correct_answer, int max_guesses){
char guessed_char;
int correct_case = 0;
int guessed_case = 0;
int guessed_char_interval1, guessed_char_interval2;
do {
printf("letter?\n");
scanf(" %c", &guessed_char);
printf("guessed_char is: %d\n", guessed_char);
printf("correct_answer is: %d\n", correct_answer);
printf("guessed character is lower character? 0:no. Else:Yes. (%d)\n", islower(guessed_char));
printf("guessed letter is %c\n", guessed_char);
if (guessed_char < correct_answer){
printf("too low\n");
}
else if (guessed_char > correct_answer){
printf("too high\n");
}
else if (guessed_char == correct_answer){
if (islower(guessed_char)){
guessed_case = 1;
}
if ( islower(correct_answer)){
correct_case = 1;
}
if (guessed_case == correct_case){
return 1;
}
else{
printf("wrong case\n");
}
}
max_guesses--;
printf("max_guesses now: %d\n", max_guesses);
} while (max_guesses > 0);
}
我知道代码还没有完成,我还没有修复它。但我无法编译它以进一步测试它。任何帮助将不胜感激!