Search code examples
cchar-pointer

Adding an int into middle of char* (In C)


Was wondering how it were possible to have an int in the middle of a char*, as such:

char * winning_message =
"Congratulations, you have finished the game with a score of " + INT_HERE +
"                 Press any key to exit...                   ";

Solution

  • With this:

    char winning_message[128]; // make sure you have enough space!
    sprintf(winning_message, "Congratulations, you have finished the game with a score of %i. Press any key to exit...", INT_HERE);