gpt4 book ai didi

c - C 中的函数问题 : Expected declaration before 'int' /'char' , 函数参数太少以及其他一些问题

转载 作者:行者123 更新时间:2023-11-30 18:41:19 24 4
gpt4 key购买 nike

好吧,首先,我应该让大家知道我是一个相对较新的程序员,而且我似乎无法获得正确的功能,所以我深表歉意如果这些确实是愚蠢/明显的问题,请提前。

无论如何,现在开始实际编程。这是一个学校项目,有点像刽子手。我已经花了好几个星期的时间,我即将完成,但这些讨厌的错误妨碍了我,我就是无法修复它们!

My beautiful errors

如果有人可以帮助我消除最后几个错误,我将非常感激!再说一次,这里是初学者程序员,我可能犯了一些令人畏缩的错误。也很抱歉代码太长..

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

typedef struct {
char title[50];
char hidden[50];
}Title;


void Film(Title* pT)
{
int i=0;
int number;
char movies[44][50];

FILE *fp = NULL;
fp = fopen("Film.txt", "r");

for(i=0; i<44; ++i)
{
fgets(movies[i], sizeof(movies[i]), fp);
}


fclose(fp);


number = (rand() % 44);
strcpy(pT->title, movies[number]);
}

char Star(Title* pT, char lowerc, char higherc, char character)
{
int val;
char c;
int lenMovie;

lenMovie = strlen(pT->title);
strcpy(pT->hidden, pT->title);

for(val=0; val <= lenMovie; val++)
{

c = pT->hidden[val];



if(c == lowerc || c == higherc)
{
pT->hidden[val] = character;
}


else if(c >= 'a' && c<= 'z')
{

pT->hidden[val] = '*';
}


else if(c >= 'A' && c<= 'Z')
{

pT->hidden[val] = '*';
}


else
{

pT->hidden[val] = c;
}

}

printf("%s", pT->hidden);
}


char Film_Guess(Title* pT, int attempt)
{

int guess[50], answer, size;

printf("What movie do you think it is: ");
scanf("%s", &guess);

size = strlen(pT->title);
answer = strncmp(pT->title, guess[50], size);


if(answer = 0)
{
printf("You beat the Film Genie, nce work!");
return 0;
}


else
{
attempt++;
return main();
}

}


int main(void)
{

char option;
int attempt = 0;
char lowerc, higherc, character, reply;

Title t;
srand(time(NULL));

printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t Welcome Player\n\n\n");




while(attempt <= 5)
{


printf("\nWould you like to try: ");
scanf("%c", &reply);


if(reply == 'y' || reply == 'Y')
{

Film (&t);
Star(&t, lowerc, higherc, character);

printf("\n Would you like to guess a character(c) or the whole film(f):");
scanf("%c",&option);



if(option =='c' || option =='C')
{

printf("\nPlease enter a character: ");
scanf("%c", &character);

lowerc = tolower(character);
higherc = toupper(character);

Star(&t, lowerc, higherc, character);


}


else if(option =='f' || option =='F')
{

Film_Guess(&t, attempt);

}

else
{

printf("\nInvalid response");
return main();

}


}




else{
break;
}

}




if(reply == 'n' || reply == 'N')
{

printf("\nLoser");
return 0;

}



else
{

printf("\nInvalid response");
return main();

}

}

最佳答案

我发现的一些错误(可能还有更多):

  1. strncmp() 接受两个 char* 参数,您提供一个 int* 作为其中之一。检查联机帮助页:http://www.manpagez.com/man/3/strncmp/

  2. 第 117 行:Star(&t, char lowerc, char highc, char character); -- 在传递参数时不应提供类型,仅在声明参数时(*下面的注释)。

  3. 第 129 行:Star (&t); -- 您的函数声明有 4 个参数。您不能只提供一项,您必须提供全部四项。

  4. 第 135 行:Film_Guess(&t, int attempts); -- 与第 117 行相同的问题

*注意:如果您对“参数”和“参数”感到困惑,请参阅 this question/answer .

关于c - C 中的函数问题 : Expected declaration before 'int' /'char' , 函数参数太少以及其他一些问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22417252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com