So I am trying to use char array in C to copy from one array to another, each element at a time, however, I am stuck at this part. I did try to research but may be I'm a dumb or what not, I still could not get it right. Here is my code:
Say I have two array
char arr1[1000][3]
char arr2[1000][3]
So wHat I mean is that [3] equal length of the string and each array has 1000 elements. So arr1[0] = "AB\0"
I can't, obviously, do arr1[i] = arr2[i]; won't work of course, I did try strcpy but don't quite get it right. Please help me out a bit, thank you :)
Here a portion of it, the specific function I writing: Please just answer the one I ask, I can do this easily in Java but I really learning C so... An example would be nice :D
//build stacks
card_pos_ptr add_card(card_pos_ptr head, char card_list[1000][3], int index){
int i,k = 0;
int start_index = index;
card_pos_ptr current = head;
for(i=0;i<13;i++){
for(k=0;k<4;k++){
if(current->card_stack == NULL){
card_ptr node = (card_ptr)malloc(sizeof(card));
strcpy(node->card_name,);
node->up = false;
node->down = NULL;
start_index++;
}else{
card_ptr node = (card_ptr)malloc(sizeof(card));
//node->card_name[0] = card_list[start_index];
node->up = false;
node->down = current->card_stack;
current->card_stack = node;
start_index++;
}
}
current = current->next_pos;
}
}
memcpy?memcpy, unless there's something preventing you from doing that.memcpy()orstrcpy()the data. Since you know they're all 2-char strings with a terminator,strcpy()is somewhat pointless. I'dmemcpy()it over if I was told to do it this way.