Thursday, 15 January 2015

c - Changing one character in a char* array without converting to char[][] -



c - Changing one character in a char* array without converting to char[][] -

i have one-dimensional array of string literals of different lengths so:

char *map[] = { "abc", "abcdef", ... };

i alter character in array map[y][x]='x';, not (and should not) work according wikipedia. read declaring char map[][] prepare bug. however, big array converting char map[][] impractical. there way accomplish want?

#include <stdio.h> #define cnv(x) (char []){ x } int main(void){ char *map[] = { cnv("abc"), cnv("abcdef"), //... }; map[1][2]='c'; printf("%s\n", map[1]);//abcdef homecoming 0; }

c arrays segmentation-fault

No comments:

Post a Comment