我正在尝试用函数编写C main()程序。程序在main()中请求一个字符,然后将其传递给一个函数,然后打印输入的字符并将该字符以大写形式返回给main()。在main()中,将打印新的大写字符。
我能够读取该字符并将其转换为大写字母,但无法通过“convert”函数打印输入的字符。输出应该是这样的:Sample output。以下是我到目前为止所做的工作。任何帮助表示赞赏。
#include <stdio.h>
#include <ctype.h>
char convert(char a1);
int main (void)
{
char lower, upper;
printf("Please enter a lowercase character: ");
scanf("%c",&lower);
upper = convert(lower);
printf("(from main) Uppercase character: %c\n",upper);
return(0);
}
char convert(char a1)
{
char result;
printf("Entered character: %c",lower); /*This statement is to be printed*/
result = toupper(a1);
return (result);
}
答案 0 :(得分:0)
您需要将以下第1行和第2行添加到您的函数convert
:
char convert(char a1)
{
char result;
printf("Converting to uppercase ...\n"); // line-1
printf("(from function) Entered character is: %c\n", a1); // line-2
result = toupper(a1);
return (result);
}
输出:
Please enter a lowercase character: t
Converting to uppercase ...
(from function) Entered character is: t
(from main) Uppercase character: T