I want to do the following
char a[] = { \'A\', \'B\', \'C\', \'D\'};
But I do not want to write these characters separately. I want somethi
This compiles fine on gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4).
const char s[] = "cheese";
int main()
{
return 0;
}
Perhaps your character array needs to be constant. Since you're initializing your array with characters from a constant string, your array needs to be constant. Try this:
#define S "ABCD"
const char a[] = { S[0], S[1], S[2], S[3] };
const char S[] = "ABCD";
This should work. i use this notation only and it works perfectly fine for me. I don't know how you are using.
Another option is to use sprintf.
For example,
char buffer[50];
sprintf( buffer, "My String" );
Good luck.
Simply
const char S[] = "ABCD";
should work.
What's your compiler?