2

I have an array of string declared like so:

char parts[PART_COUNT][PART_MAX];

Then i made a function which takes a string and a array of strings and splits it into those parts, which is declared like this:

WORD PartString(const char *str, char **parts, char sep);

I can seem to read at parts[i][j], but if i try to assign like this:

parts[i][j] = str[x];

I get this error:

Unhandled exception at 0x012614d8 in remote.exe: 0xC0000005: Access violation writing location 0xcccccccc.

Can anyone tell me a way to do this in C? thanks.

10
  • 1
    char parts[M][N] is not the same as char **parts; if you've performed a cast in order to get the compiler to stop complaining, then that will be the cause of your problem. Commented Jul 3, 2011 at 18:38
  • possible duplicate of Converting multidimensional arrays to pointers in c++ Commented Jul 3, 2011 at 18:40
  • compiler isn't complaining, i passed simply as PartString(buffer, parts, '.'); Commented Jul 3, 2011 at 18:40
  • That should definitely cause a compiler warning or error message. Commented Jul 3, 2011 at 18:41
  • 2
    You urgently need to deal with the fact that your compiler is broken. Commented Jul 3, 2011 at 18:44

1 Answer 1

1
#define PART_MAX      1024
#define PART_COUNT    4

Ok, managed to fix it, i had my compiler warnings off and when i turned them back on i got this:

'char **' differs in levels of indirection from 'char [4][1024]'

Heres the new declaration which lets me modify the strings in the array:

WORD PartString(const char *str, char (*parts)[PART_MAX], char sep)

THen i just pass as:

PartString(buffer, parts, '.');
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.