gpt4 book ai didi

c - 函数 'enterChar' [-Wimplicit-function-declaration] 的隐式声明

转载 作者:太空狗 更新时间:2023-10-29 15:11:14 24 4
gpt4 key购买 nike

<分区>

关于我的 C 程序,我有两个问题:1) 在 main() 中,C = enterChar();N = enterNum();leftJustifiedPic(C , N);, rightJustifiedPic(C, N); 都给我 函数的隐式声明。那有什么意思?我习惯了 Java,在代码方面,它在 C 中是否有点不同?

2) 在方法 enterChar() 中,我得到了 conflicting types for 'enterChar' 错误,并且再次不明白它的含义和发生的原因。如果 Eclipse (Cygwin-GCC) 与问题有关,我正在研究它。

smb 能否详细说明此类错误和警告?我很感激!

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

int main()
{
printf("Welcome to the menu!");
printf("The menu is:\n1. Enter/Change Character\n2. Enter/Change Number\n3. Print Triangle Type 1(Left Justified)\n4. Print Triangle Type 2(Right Justified)\n5. Quit");
printf("\n");
printf("Now enter a number from the menu from 1 through 5: \n");
int num = 0;
scanf("%d", &num);

char C;
int N = 0;
switch(num){
case 1:
C = enterChar();
break;
case 2:
N = enterNum();
break;
case 3:
leftJustifiedPic(C, N);
break;
case 4:
rightJustifiedPic(C, N);
break;
default:
printf("Smth is wrong!");
}

return 0;
}

char enterChar(){
printf("Enter your input as a character. Only 'C' and 'c' are allowed!\n");
char input = 0 ;
scanf("%c", &input);
while(input != 'c' || input != 'C'){

if(input != 'C' || input != 'c'){
printf("You have to enter 'C' or 'c'. Try again!");
}

}
return input;
}

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