开发者

Passing multi-dimensional array to function in c?

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.开发者_如何学Python

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


#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, '.');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜