函数将打印新行,但不会输出变量结果

时间:2017-10-27 03:25:48

标签: c function variables

我的代码如下:

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

int isUpper(char*);
int causeUpper(char*);
int causeLower(char*);
int isNumber(char*);

int main(void)
{
    char userInput[1];
    int caseResult;
    int numResult;
    char newUpper;
    char newLower;

    printf("Input a character: ");
    scanf("%c", userInput);

    numResult = isNumber(userInput);

    if (numResult == 0)
    {
        caseResult = isUpper(userInput);
        if (caseResult == 0);
        {
            newUpper = causeUpper(userInput);
            printf("%c\n", newUpper);
        }//close of if statement

        if (caseResult == 1)
        {
            newLower = causeLower(userInput);
            printf("%c\n", newLower);
        }//close of if statement

    }//close of if statement

    if (numResult == 1)
    {
        printf("%d\n", userInput);

    }//close of if statement

    if (userInput == ",")
    {
        exit;
    }//close of if statement

}//close of main function

int isUpper(char* userInput)
{
    if (*userInput > 64 && *userInput < 91)
    {
        return 1;
    }//close of if statement

    else
    {
        return 0;
    }//close of else statement

}//close of isUpper function

int causeUpper(char* userInput)
{
    *userInput = *userInput - 32;
    return *userInput;

}//close of causeUpper function

int causeLower(char* userInput)
{
    *userInput = *userInput + 32;
    return *userInput;

}//close of causeLower function

int isNumber(char* userInput)
{
    int numResult;

    if (*userInput >= '0' && *userInput <= '9')
    {
        numResult = 1;
        return numResult;

    }//close of if statement

    else
    {
        numResult = 0;
        return numResult;

    }//close of else statement

}//close of isNumber function

我对我的代码进行了建议编辑,当我运行它时输入了&#39; a&#39;变成'A&#39;,这样可行,但是当我尝试测试下一个功能时,输入A&#39; A&#39;返回此而不是小写字母:

 !
 A

如何修复此错误,以便在输入大写字母时只输出小写字母?

0 个答案:

没有答案