Thursday, July 9, 2009

Need help reading in names in a 2d array. (C++)?

any kinds c++ programmers could care to assist me in how would u write a code to enter 6 names in a 2d array (C++). i've tried severa codes but no success. i've even tried entering then in simple arrays and then assign it to the 2D but no success. please help me!!. thanks in advance.

Need help reading in names in a 2d array. (C++)?
char names[6][10]; // make the 10 greater than the max length of your names





strcpy( names[0], "joe" );


strcpy( names[1], "bob");


strcpy( names[2], .





and so on.





names[0][0] will be 'j'


names[0][1] will be 'o'


names[0][2] will be 'e'


names[0][3] will be '\0' (just a zero)


names[0][4] ....[0][9] will be undetermined


names[1][0] is 'b', then 'o', etc.





hope that gets you started.





for user input, use "cin%26gt;%26gt;string" then do the strcpy


No comments:

Post a Comment