Problem with chars and char arrays

This is a discussion on Problem with chars and char arrays within the C++ Programming forums, part of the General Programming Boards category; Whenever I have a char and want it to equal " " (a space) such as [code] char ch; ch ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    15

    Angry Problem with chars and char arrays

    Whenever I have a char and want it to equal " " (a space) such as

    [code]
    char ch;
    ch = " ";
    [\code]

    I get this really annoying error that I cannot convert a char[2] to a char. the same thing happens with arrays.

    [code]
    char longch[21];
    longch[1] = " ";
    [\code]

    This will happen with any alphanumeric character. I would like to know how I can get around this.

    Thanks!
    -Zagaberoo

  2. #2
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    try using single quotes instead like so:
    Code:
    char ch;
    ch = ' ' ;
    
    char longch[21];
    longch[1] = ' ' ;
    You were tring to assign a sting to a single char(yes I know you only had one char in the " " but the compilers will see it as a string constant because of these " ").
    Last edited by Dohojar; 09-27-2003 at 08:46 AM.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    15
    Thank you SO much!

  4. #4
    Registered User Dohojar's Avatar
    Join Date
    Feb 2002
    Posts
    115
    your welcome. Glad I could help.
    Dohojar Moajbuj
    Time is the greatest teacher, too bad it kills all its students

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 10-22-2008, 07:20 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Passing pointers to arrays of char arrays
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 03-31-2006, 04:31 AM
  4. concatenating single chars to multi char arrays
    By TJJ in forum C Programming
    Replies: 7
    Last Post: 11-20-2003, 03:09 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21