C – I can’t get my stringcopy and stringcat function to work on a 2d array

I'm trying to combine a char type 2d array with a string (specifically "*") and a number which is already in the form of a string.

Let's say I have a list of numbers (that have a string datatype) on a 2d array called bingo char bingo[n][n], I then wanted to copy this to a new 2d array called char finalbingo[n][n] along with a "*" with a stringcopy and strcat function.

(e.g: bingo[0][0] contain a string "5", this will become "*5" on finalbingo)

Here is my code:

int l,m,q;
char number;
char finalbingo[n][n];

for (l = 0; l < n; l++){
    for (m = 0; m < n; m++){
          number = bingo[l][m];
          strcpy(&finalbingo[l][m], "*");
          strcat(&finalbingo[l][m], &number);
    }
  }
 
 printf("%c", finalbingo[0][0]);

It does not seem to be working and I'm not sure why. Thanks for taking your time to help me.



Read more here: https://stackoverflow.com/questions/64893329/c-i-cant-get-my-stringcopy-and-stringcat-function-to-work-on-a-2d-array

Content Attribution

This content was originally published by KittyCat at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: