c - Passing multi-dimensional arrays into functions and editing values -
this question has answer here:
i'm working on creating simple wordsearch generator having problem passing 2 dimensional array through function , editing value inside. have declared array in main such:
char tablevalues[xsize-1][ysize-1];
i'm filling each point in array - in main, passing through function fills array random letters , returns.
void filltable(char *tablevalues){ ( int = 0 ; < xsize ; i++ ){ ( int j = 0 ; j < ysize ; j++ ){ if ( tablevalues[i][j]=='-') tablevalues[i][j] = "abcdefghijklmnopqrstuvwxyz"[rand () % 26]; } } }
my problem error gets flagged @ "tablevalues[i][j]" parts, i'm not sure how else i'd edit individual points in array pointers. appreciated, thanks
i calling function as
filltable((char *)tablevalues);
try this,
void filltable(char *tablevalues){ ( int = 0 ; < xsize ; i++ ){ ( int j = 0 ; j < ysize ; j++ ){ if ( *((tablevalues +i*(xsize-1))+j)=='-') *((tablevalues+i*(xsize-1))+j) = "abcdefghijklmnopqrstuvwxyz"[rand () % 26]; } } }
Comments
Post a Comment