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.

Nicolas Kaiser
  • 1,628
  • 2
  • 14
  • 26
Kaije
  • 2,631
  • 6
  • 38
  • 40

1 Answers1

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, '.');
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
Kaije
  • 2,631
  • 6
  • 38
  • 40