Copy array of strings into another array in C -
i'm making word search program in c takes user input , chooses 1 of global arrays of words , uses generate word search. works when use 1 of global arrays not choice, want copy contents of category arrays, depending on users choice newarray can used word search. program crashes after entering option @ moment, here's have.
switch(choice) { case 1: chosearray(newarray, masseffect); break; case 2: chosearray(newarray, fallout3); break; case 3: chosearray(newarray, elderscrolls); break; case 4: chosearray(newarray, gameofthrones); break; case 5: chosearray(newarray, breakingbad); break; default: printf("enter valid option!"); } void chosearray(char** newarray, char** category) { int i; for(i=0;i<6;i++) { strcpy(newarray[i], category[i]); } }
the arrays , declared globally now
char gameofthrones[6][250] = {"kingslanding", "tyrian", "stark", "lanisters", "westeros", "winterfell"}; char breakingbad[6][250] = {"jesse", "walt", "heisenberg", "saul", "gustavo", "breakfast"}; char newarray[6][250];
if declare word lists in form ...
char gameofthrones[6][250] = { ... };
then arrays of arrays of char
s. function parameter type char **
pointer char
pointer, not directly comparable. compiler should have thrown fit this.
supposing newarray
of same type base word lists, should declare function so:
void chosearray(char newarray[][250], char category[][250]) { ... }
... or possibly so:
void chosearray(char (*newarray)[250], char (*category)[250]) { ... }
... match actual argument types. body of function works as-is in case.
Comments
Post a Comment