-8

When I run and compile the code, I get errors that A and Z, and a and c are both undefined, how do I fix this ?

char toUpper ( char c ) {

    if ( C >= a + c <= z) 
        -32;
    return c;

} // ends toUpper

char toLower ( char c ) {

    if ( c >= A + c <= Z ) 
        +32;

} // ends toUpper
nhahtdh
  • 55,989
  • 15
  • 126
  • 162

3 Answers3

3

Quote the letters in single quotes to form character literals, like this:

'a'
Zach
  • 7,730
  • 3
  • 21
  • 26
1

A brief summary:

  • You need quotes around character constants.
  • Your function should return something that is an upper or lower case character.
  • When testing for two conditions, use && for "logical and" and || for "logical or"

A logical and is true if BOTH sides of the && is true. A logical or is true if ONE side of the || is true.

I'm not "editing your code to fix it" because I'm pretty sure you are the one learning how to write C, and if I just typed in the "correct code" here, you would just copy it and paste it into your code, and learn absolutely nothing.

Mats Petersson
  • 126,704
  • 14
  • 140
  • 227
1

There are 2 main problems in your code.

The first is that you are using a instead of 'a'. When the compiler sees a it attempts to interpret it as an identifier. This means it should refer to an argument, local, function name, etc ... The intent of your code though is for it to mean the character a (first letter of the alphabet). Putting the single quotes around a single letter causes the compiler to interpret it as a character literal.

The second issue is that your conditional statement is incorrect. You are trying to see if C is both greater than or equal to 'a' and less than or equal to 'z'. This type of boolean comparison is done with the && operator in C. It is only true if both the left hand side and right hand side of the && are also true

if ( C >= 'a' && c <= 'z') 
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • "Why doesn't `if (c >= 'a' && c <= 'z')` work when the character set is EBCDIC?"... Just use `islower`, ffs! – autistic Mar 05 '13 at 23:30