Note that there are some explanatory texts on larger screens.

plurals
  1. POJoining 8 strings to form 1 string in C
    text
    copied!<p>I am doing a <code>C</code> programming school project. In one part of the project, I need to join every 8 strings (each 4 characters in length) to form 1 string (each 32 characters in length). </p> <p>For example, <code>char *holdBinary[16]</code> holds 16 strings such as:</p> <pre><code>holdBinary[0] = "0000"; holdBinary[1] = "0000"; holdBinary[2] = "0000"; holdBinary[3] = "0000"; holdBinary[4] = "0000"; holdBinary[5] = "0000"; holdBinary[6] = "0000"; holdBinary[7] = "0000"; holdBinary[8] = "0000"; holdBinary[9] = "0000"; holdBinary[10] = "0010"; holdBinary[11] = "1010"; holdBinary[12] = "0000"; holdBinary[13] = "0000"; holdBinary[14] = "0000"; holdBinary[15] = "0000"; </code></pre> <p>I need to join every 8 strings in <code>holdBinary</code> to form 1 string which is held in <code>holdRange</code> char array. Thus, the results: <code>holdeRange[0] = "00000000000000000000000000000000"</code> which is formed by <code>holdBinary[0]</code>, <code>holdBinary[1]</code> .... <code>holdBinary[7]</code> and <code>holdeRange[1] = "00000000001010100000000000000000"</code>.</p> <p>Here is the code:</p> <pre><code>char holdRange[2][33]; // I changed here and it works correct now int hold = 0; int z = 0; int index2 = -1; while(z&lt;16) { if(z%8 == 0) { index2++; strcpy(holdRange[index2] , holdBinary[z]); } else { strcat(holdRange[index2] , holdBinary[z]); } z++; } printf("%s" , holdRange[0]); --&gt; prints 0000000000000000000000000000000000000000001010100000000000000000 printf("\n"); printf("%s" , holdRange[1]); --&gt; prints 00000000001010100000000000000000 </code></pre> <p>Thus, <code>holdRange[0]</code> is not equal to what must be. How can I fix it?</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