0

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.

3
  • 1
    The code as-is doesn't make sense at all. What are you trying to do? Commented Apr 12, 2013 at 20:10
  • This is one of two arrays being used in an aho-corasick implementation. This is some example code i've been given to try and understand the algorithm, it doesn't contain the failure links. Commented Apr 12, 2013 at 20:12
  • I doubt this be the actual code, since it is invalid. There's nothing to understand in it until someone doesn't fix its syntax. Only then will it be possible to make sense of it. Commented Apr 12, 2013 at 20:13

1 Answer 1

1

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",
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.