【发布时间】:2015-12-18 15:39:10
【问题描述】:
我有两个关于我的 C 程序的问题:
1) 在main() 中,C = enterChar();、N = enterNum();、leftJustifiedPic(C, N);、rightJustifiedPic(C, N); 的行都给了我implicit declaration of function。那有什么意思?我已经习惯了 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;
}
【问题讨论】:
标签: c