I have the following:
char rank[100][100];
int score = 5;
strcpy(rank[0], "%d" score);
However, strcpy()
does not accept these arguments. Is there any way to append a formatted string into my array?
I have the following:
char rank[100][100];
int score = 5;
strcpy(rank[0], "%d" score);
However, strcpy()
does not accept these arguments. Is there any way to append a formatted string into my array?
You could use sprintf
:
char rank[100][100];
int score;
sprintf(rank[0], "%d", score);
Note however that snprintf
is the buffer overflow-safe alternative.
There is no direct way to do this with strcpy()
.
However, you can make use of snprintf()
first to prepare your string and the use the same as the second argument of strcpy()
.
FWIW, in this case, you can directly use snprintf()
on rank[n]
, also.