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

Recommended Answers

All 5 Replies

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.

I was thinking that too, but figured he wanted to ... transpose it for his own reasons.

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.