[英]About Conflicting Types Error in C Programming
can anyone help me to find the why I am getting conflicting type of error in in the toLower(char letter) function.谁能帮我找出为什么我在 toLower(char letter) 函数中遇到冲突类型的错误。
#include <stdio.h>
int main()
{
char letter;
printf("Enter the upper case letter..!!");
scanf("%c", &letter);
char new_letter = toLower(letter);
printf("The new letter is %c " , new_letter);
return 0;
}
char toLower(char letter)
{
int distance = (int)'a' - (int)'A'; // Calculating the distance between letters...
char new_letter = letter + (char) distance;
return new_letter;
}
In C, you must always declare the function prior to calling it.在 C 中,您必须始终在调用函数之前声明该函数。 This is what Tom Karaz has pointed out in a comment to your post.
这是 Tom Karaz 在对您的帖子的评论中指出的。
There are two possible solutions.有两种可能的解决方案。
Solution 1:解决方案1:
#include <stdio.h>
char toLower(char letter)
{
int distance = (int)'a' - (int)'A'; // Calculating the distance between letters...
char new_letter = letter + (char) distance;
return new_letter;
}
int main()
{
char letter;
printf("Enter the upper case letter..!!");
scanf("%c", &letter);
char new_letter = toLower(letter);
printf("The new letter is %c " , new_letter);
return 0;
}
Solution 2: This solution makes use of function prototyping.解决方案 2:此解决方案使用函数原型。 That is on the second line I have taken the function signature and declared that prior to where I invoke a function call.
那是在第二行,我采用了函数签名并在调用函数调用之前声明了它。 The function prototype and the function signature must be identical.
函数原型和函数签名必须相同。
#include <stdio.h>
char toLower(char letter); // function prototype
int main()
{
char letter;
printf("Enter the upper case letter..!!");
scanf("%c", &letter);
char new_letter = toLower(letter);
printf("The new letter is %c " , new_letter);
return 0;
}
char toLower(char letter)
{
int distance = (int)'a' - (int)'A'; // Calculating the distance between letters...
char new_letter = letter + (char) distance;
return new_letter;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.