As a newbie I was trying to declare an ASCII string ending with a "0", but got a compiler error.
What is wrong?Code:constant char STRING[7] = {"string",0};
As a newbie I was trying to declare an ASCII string ending with a "0", but got a compiler error.
What is wrong?Code:constant char STRING[7] = {"string",0};
Because when you initialize a string, you need to do it one character at a time.
Like this:
or you can do this...Code:const char STRING[] = {'s', 't', 'r', 'i', 'n', 'g', '0'};
Code://Also, include <string.h> char STRING[10]; strcpy(STRING,"string"); strcat(STRING,"0");
Last edited by SlyMaelstrom; 10-30-2005 at 02:09 AM.
Sent from my iPadŽ
Originally Posted by SlyMaelstromCode:const char astringy[] = "You do?";
Quzah.
Hope is the first step on the road to disappointment.
Ok you don't... but you could.
Sent from my iPadŽ
you don't have to explicitly put the terminating 0 there, the compiler will do that for you. You also don't need the braces, nor specify the string size unless you want the character array to be larger than the initialization string.Originally Posted by Andy_P
Code:constant char STRING[] = "string";
And it's const, not constant.Originally Posted by Ancient Dragon