Nexus490
Nexus490

Reputation: 329

2D Array set up in C

I'm trying to write some code from an example i've been given. The line which is causing the problem is:

unsigned char search[][256] = '\04' "TEST", '\04' "DEMO";

I have very little experience with C, am I right in thinking this is a 2D array and if so what is being assigned to it?

The error i'm getting is "expected ',' or ';' before string constant". I've tried putting both of those before the strings but that didn't seem to help.

Could someone explain what this line means and perhaps whats wrong with it.

Upvotes: 0

Views: 103

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 224546

If you are trying to initialize search so that its first element is an array of 256 char containing the character with number 4, then characters T, E, S, and T, then null characters and the second element is an array with the character with number 4, then D, E, M, and O, then null characters, then the syntax is:

unsigned char search[][256] = {"\04TEST", "\04DEMO"};

If that is not what you want, you need to explain. The above makes some sense if the \04 is intended to be the length of the remaining characters. If you want to separate the length from the other characters so that it is clear, you could use:

unsigned char search[][256] = {"\04" "TEST", "\04" "DEMO"};

or:

unsigned char search[][256] =
{
    "\04" "TEST",
    "\04" "DEMO",
};

Upvotes: 1

Related Questions