0

i'm having problem in executing this statement....
error expression syntax

switch(col)
    {
            case 1:text[]={"0x00000000"};
        break;
            case 2:text[]={"0x00FFFFFF"};
        break;
            case 3:text[]={"0x0000FF00"};
        break;
            case 4:text[]={"0x00FF0000"};
        break;
            case 5:text[]={"0x00C000C0"};
        break;
            case 6:text[]={"0x000000FF"};
        break;
            case 7:text[]={"0x0000FFFF"};
        break;
            case 8: text[]={"0x00FFFF00"};
        break;


    }


char text[10] is global.

please help me out.............

Edited by Reverend Jim: Fixed formatting

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by jonsca
0

Use strcpy to copy those values into the character array:

#include <cstring> //to access strcpy
switch(col)
{
   case 1:  strcpy(text,"0x00000000");
   break;
      //etc.
}

You can only assign text to a character array in the manner that you are trying when it is first declared.

Edited by jonsca: n/a

1

char text[10]

You need to increase the size of that array by one, if you intend to copy a literal such as "0x00000000" into it (you must account for the terminating '\0' character). Otherwise, you'll be writing out of bounds, which is not allowed.

PS. Maybe consider using std::string s instead of char arrays.

Votes + Comments
Good catch
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.