Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <a href="http://www.daniweb.com/forums/thread11049.html" rel="nofollow noreferrer">itoa</a> function to convert the integer to a string.</p> <p>You can use <a href="http://en.wikipedia.org/wiki/Strcat" rel="nofollow noreferrer">strcat</a> function to append characters in a string at the end of another string.</p> <p>If you want to convert a integer to a character, just do the following - </p> <pre><code>int a = 65; char c = (char) a; </code></pre> <p>Note that since characters are smaller in size than integer, this casting may cause a loss of data. It's better to declare the character variable as <code>unsigned</code> in this case (though you may still lose data).</p> <p>To do a light reading about type conversion, go <a href="http://en.wikipedia.org/wiki/Type_conversion" rel="nofollow noreferrer">here</a>.</p> <p>If you are still having trouble, comment on this answer.</p> <p><strong>Edit</strong></p> <p>Go <a href="https://stackoverflow.com/questions/308695/c-string-concatenation/308712#308712">here</a> for a more suitable example of joining characters.</p> <p>Also some more useful link is given below - </p> <ol> <li><a href="http://www.cplusplus.com/reference/clibrary/cstring/strncat/" rel="nofollow noreferrer">http://www.cplusplus.com/reference/clibrary/cstring/strncat/</a></li> <li><a href="http://www.cplusplus.com/reference/clibrary/cstring/strcat/" rel="nofollow noreferrer">http://www.cplusplus.com/reference/clibrary/cstring/strcat/</a></li> </ol> <p><strong>Second Edit</strong></p> <pre><code>char msg[200]; int msgLength; char rankString[200]; ........... // Your message has arrived msgLength = strlen(msg); itoa(rank, rankString, 10); // I have assumed rank is the integer variable containing the rank id strncat( msg, rankString, (200 - msgLength) ); // msg now contains previous msg + id // You may loose some portion of id if message length + id string length is greater than 200 </code></pre> <p><strong>Third Edit</strong></p> <p>Go to this <a href="http://www.daniweb.com/forums/post701067.html#post701067" rel="nofollow noreferrer">link</a>. Here you will find an implementation of <code>itoa</code>. Use that instead.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload