Monday, May 24, 2010

How do i insert data into a 2-dim array in c-language, and then print it?

i need to make all the values in the array to equal '_' which just represents a space which will later be modified


this is how i started the array


char chararr[60][40];


i need to use a 'for' loop or similar in order to achieve this.





after all the information is in the array i need to print it using the printf command. the way this needs to be done is by printing each value individually so that it looks like an actual matrix, which means a new line should be started after each entire row is printed


i need this urgently so please help me out. and i would greatly appreciate it if you could give me the code for either task


thanks

How do i insert data into a 2-dim array in c-language, and then print it?
//to initialize your array


char chararr[60][40];


int i;


int j;


for(i = 0; i %26lt; 60; i++)


{


for(j = 0; j %26lt; 40; j++)


{


chararr[i][j] = '_';


}


}





//to print your array





int i;


int j;


for(i = 0; i %26lt; 60; i++)


{


for(j = 0; j %26lt; 40; j++)


{


printf("%c", char[i][j]);


}


printf("\n");


}





notice how similar they are? nested for loops are how you'll always step through multi-dimensional arrays. If you need some clarification for the code above, send me an email.





Good luck.


No comments:

Post a Comment