0

hi,

its been a long time since i've had to work on c and i've stumbled. I'm basically trying to get a string[5] into a 2d array stringarray[10][1]

char string[5];
char stringarray[10][1];

void workfunction();

int main(){

workfunction();

for(i=0;i<10;i++){
printf("%s", stringarray[i][0]);
}

}

workfunction(){

for(j=0;j<10;J++){
//does something to get me 2 int's x & y
sprintf(string,"%d,%d-",x,y);
string[j][0] = string; <-- HERE IS THE PROBLEM
}
}

i thought of using strcpy but that also has the reverse error (char to char pointer)

any help would be greatly appreciated thanks

4
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by EvilOrange
0

First consider not globalising all the variables and consider passing them by pointer or something from main().

Second, the line should be stringarray[j][0] = string[j]; That should be it, methinks. Work on indentation too, perhaps.

0

EvilOrange> string[j][0] = string; <-- HERE IS THE PROBLEM

string[j][0] is a space to hold a character
string, on the other hand, is an array of characters. For sure there's going to be a problem if you try to push a bunch of character where only one can live.

0

EvilOrange> string[j][0] = string; <-- HERE IS THE PROBLEM

string[j][0] is a space to hold a character
string, on the other hand, is an array of characters. For sure there's going to be a problem if you try to push a bunch of character where only one can live.

many thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.