Question

I'm trying to change the case of a letter entered by the user and store a lower case and a higher case version of the letter in variables. I've written the code below but it's having issues running. Anyone point out what's causing the problems?

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

char CaseChange(character){

    int lowerc, higherc;


    if(isupper(character)){
        lowerc = tolower(character);
        printf("%s", lowerc);
    }
    else{
        higherc = character;
        printf("%s", higherc);

    }
    return;
}

int main(void){

    char character;

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

    CaseChange(character);
    return 0;
}
Was it helpful?

Solution

There are two problems in your code:

  1. printf("%s", ...) is meant for outputting strings (char* and const char*), not single characters. Use printf("%c", ...)
  2. You forgot to #include <ctype.h>

Side-note: You don't have to check if a character is uppercase with isupper(x). tolower(x) will leave already-lowercase characters intact.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top