-7

I cannot seem to get my program to show both values I have listed within the ''. I have it listed as 'Aa', 'Bb', and so on, but when I run the code it only shows the second letter (lowercase letter). I have tried changing up from int conversions, pointers, and other things, but cannot figure this part out. Any help is greatly appreciated!

Here is my code:

#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <string>

using std::cin;
using std::cout;
using std::endl;

int main()
{
    char letters[] = { 'Aa', 'Bb', 'Cc', 'Dd', 'Ee', 'Ff', 'Gg', 'Hh', 
        'Ii', 'Jj', 'Kk', 'Ll', 'Mm', 'Nn', 'Oo', 'Pp', 'Qq', 'Rr', 'Ss', 
        'Tt', 'Uu', 'Vv', 'Ww', 'Xx', 'Yy', 'Zz', '\0'};

    for (char * cp = letters; *cp; ++cp)
    {
        if (*cp == 0) break;
        printf("%c", *cp);
    }
    cout << endl;
}

It displays the alphabet, but just the lowercase values. How can I get it to display both the uppercase and lowercase values in the ''?

chrisaycock
  • 36,470
  • 14
  • 88
  • 125
  • `'Aa'` is not a `char`. You can't do what you're trying to do with a `char[]`; use strings. – user2357112 Feb 07 '17 at 01:44
  • 2
    See [Single quotes vs. double quotes in C or C++](http://stackoverflow.com/questions/3683602/single-quotes-vs-double-quotes-in-c-or-c). When you try to fit `'Aa'` into a `char` (which can hold only a single character), it gets truncated and turns into simple `'a'`. What was the expected effect of that? Also, I'd recommend enabling all compiler's warnings (`-Wall -Wextra` for gcc) – yeputons Feb 07 '17 at 01:45
  • Thank you, that is what i thought but all i could find was char for the array but using the string value got it to display. – The Phoenix Feb 07 '17 at 02:00
  • See also `std::toupper`, `std::tolower` and `std::transform`. – Thomas Matthews Feb 07 '17 at 02:03
  • @yeputons please write your comment as the answer. This way the question can be closed. – Black Frog Mar 04 '17 at 11:04
  • @BlackFrog done – yeputons Mar 04 '17 at 11:18

1 Answers1

1

See Single quotes vs. double quotes in C or C++. When you try to fit 'Aa' into a char (which can hold only a single character), it gets truncated and turns into simple 'a'.I'd recommend enabling all compiler's warnings (-Wall -Wextra for gcc) to avoid such kind of mistakes.

Community
  • 1
  • 1
yeputons
  • 8,478
  • 34
  • 67