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};
Printable View
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");
Quote:
Originally Posted by SlyMaelstrom
Code:const char astringy[] = "You do?";
Quzah.
Ok you don't... but you could.
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.Quote:
Originally Posted by Andy_P
Code:constant char STRING[] = "string";
And it's const, not constant.Quote:
Originally Posted by Ancient Dragon