Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arrays of pointers again

Status
Not open for further replies.

bigE

Programmer
Jun 26, 2000
2
0
0
US
Sorry I did'nt put all the information necessay in the first email. Below is the basics of what I am trying to do. I am just trying to form an array of pointers to six two-dimensional integer arrays. Afterwards I want to retrieve them and print them out. Since my last email I have tried a few other things but I am still having problems. Here's the code.<br><br><br>#include &lt;stdio.h&gt; <br>#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br><br>void displacement_from_source(int X, int u_position[4][2],int* rx_displacement[6]);<br>void print_out_arrays(int X, int* rx_displacement[6]);<br><br>// Main Program<br>void main ()<br>{<br><br>/* global variables */<br><br>int i,j;<br>int u_position[4][2]={5,6,7,8,9,10,11,12};<br>int X;<br>int* rx_displacement[6]; //array of pointers<br>int*tx; <br>int temp_array[4][2];<br><br>for (X=0; X&lt;6; X++) // go through six times to form the six integer arrays<br>{<br> displacement_from_source(X,u_position,rx_displacement);<br>}<br><br>for (X=0; X&lt;6; X++) //go through six times to print arrays<br>{<br>tx=rx_displacement[X]; //assign pointer tx the first interarray address<br>memcpy(temp_array,tx, 8*sizeof(int)); //assign this address to temp_array<br><br>&nbsp;for (i=0;i&lt;4;i++)<br>&nbsp;{<br> for (j=0;j&lt;2;j++)<br> { <br> printf(&quot;%d\n&quot;, temp_array<i>[j]);<br><br> }<br>&nbsp;}<br>}<br><br>}<br><br>void displacement_from_source(int X, int u_position[4][2],int* rx_displacement[6])<br>{<br> <br>int i,j;<br><br>int rx_array[4][2];<br>int rx_temp[4][2];<br>int* rx;<br>int* tx;<br>&nbsp;<br>memcpy(rx,rx_temp, 8*sizeof(int)); //assign the address of rx_temp to the pointer rx<br>rx_displacement[X]=rx; //assign the address of rx to the array of pointer's Xth<br> for (i=0;i&lt;4;i++)<br> {<br> for (j=0;j&lt;2;j++)<br> {<br> rx_temp<i>[j]=u_position<i>[j]; <br> }<br> }<br>}<br><br><br>
 
Here is some simple code that I threw together that shows how to use pointers with 2 dimensional arrays:<br><br>#include &lt;stdio.h&gt;<br><br>int main()<br>{<br>char (*x)[15];<br>char y[10][15];<br>int z;<br><br><br>for (z=0; z&lt;10; z++)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;sprintf( &(y[z][0]), &quot;hello %d\n&quot;, z);&nbsp;&nbsp;// Fill the array Y with data<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;x = y;&nbsp;&nbsp;// Assign the pointer X to point to the array Y <br><br>for (z=0; z&lt;10; z++)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;printf( &quot;%s&quot;, &x[z][0] );&nbsp;&nbsp;// Print out the array Y using pointer X<br>&nbsp;&nbsp;&nbsp;}<br><br>return 0;<br>} <p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href= Page</a><br>
 
Hi ,<br>&nbsp;&nbsp;&nbsp;heer I am posting you the code with lots of modificatoins. This will surle help you . If at-all you have any problem then fell free to call me ...<br><br>#include &lt;stdio.h&gt; <br>#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br><br>void displacement_from_source(int X, int u_position[4][2],int* rx_displacement[6]);<br>void print_out_arrays(int X, int* rx_displacement[6]);<br><br>// Main Program<br>void main ()<br>{<br><br>/* these are not global variables */<br><br>int i,j;<br>int u_position[4][2]={5,6,7,8,9,10,11,12};<br>int X;<br>int* rx_displacement[6]; //array of pointers<br>int*tx; <br>int temp_array[4][2];<br><br>for (X=0; X&lt;6; X++) // go through six times to form the six integer arrays<br>{<br>displacement_from_source(X,u_position,rx_displacement);<br>}<br><br>for (X=0; X&lt;6; X++) //go through six times to print arrays<br>{<br>tx=rx_displacement[X]; //assign pointer tx the first interarray address<br>memcpy(temp_array,tx, 8*sizeof(int)); //assign this address to temp_array<br><br>&nbsp;for (i=0;i&lt;4;i++)<br>&nbsp;{<br>for (j=0;j&lt;2;j++)<br>{ <br>printf(&quot;%d\n&quot;, temp_array[j]);<br><br>}<br>&nbsp;}<br>}<br><br>}<br><br>void displacement_from_source(int X, int u_position[4][2],int* rx_displacement[6])<br>{<br><br>int i,j;<br><br>int rx_array[4][2];<br>int rx_temp[4][2];<br>int* rx;<br>int* tx;<br>&nbsp;<br>memcpy(rx,rx_temp, 8*sizeof(int)); //assign the address of rx_temp to the pointer rx<br>rx_displacement[X]=rx; //assign the address of rx to the array of pointer's Xth<br>for (i=0;i&lt;4;i++)<br>{<br>for (j=0;j&lt;2;j++)<br>{<br>rx_temp[j]=u_position[j]; <br>}<br>}<br>}<br><br><br> <p>Bhaskar Bora<br><a href=mailto:bhaskar_bora@yahoo.com>bhaskar_bora@yahoo.com</a><br><a href= > </a><br>___________________________________________________________<br>
C and C++ are too Cool ... Like CoSSAP ..<br>
Ooops What's this CoSSAP...?? <br>
It's a Objected oriented language created by me ...<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top