Saturday, May 22, 2010

Programing in c++....arrays?

how do you store multiple types of information from a file into different arrays.


92 83 91 89 John Centeno


75 73 79 77 Stuart Morris


65 82 83 77 Robert Cifuentes


93 95 91 92 Miguel Kuey


84 87 92 81 Monica Liao


66 65 77 78 Linda Gonzalez


72 66 91 88 James Waggoner


68 62 77 58 Luis Amezcua


77 89 83 81 Arnoldo Ramos


92 83 95 93 Kathryn Yescas


73 78 82 75 Sylvia Shin


77 73 78 76 Tony Balogun


82 83 88 84 Yonjhen Sutoyo


66 72 64 68 Damon Vertido


79 82 85 77 Michelle Valdez


83 93 95 94 Maria Villamor


63 62 69 73 Erika Morris


88 83 84 79 Alonso Baek


82 86 91 83 Hye Dizon


75 79 82 73 Olarewaju Nayak


88 93 92 93 Albert Lane


89 95 96 90 Joseph Alan


77 75 82 78 Gerard Cendejas


(that's my input file)





trying to store the test scores in a 2D array. and the names in another 2D array. nothing i have tried has worked.





testScores[25][4] %26amp; studentName[25][21] are my array names.


%26amp; how do you get the full name of the student w/ spaces using an array?? please help!!!!

Programing in c++....arrays?
Should be close like you had..


int testScores[25][4];


char studentName[25][32];


32 would be maxim length of any students name.





I wonder what the compiler error is?





To get the last name you could just read in another string and then use a function named strcat maybe or keep the last name separate.





int testScores[25][4];


char firstName[25][32];


char lastName[25][32];
Reply:for storing names...u can use





char *s[25];


this is an array of pointers to strings...


to print any name....use








puts(s[i]); // do include%26lt;stdio.h%26gt;


this displays names containing spaces also....








to enter names from console...i.e output window, by the user





gets(s[i]);





can be used..........





if u want to read from file then read character by character from file by using getchar()


and put that in-%26gt; *(s[i]+0)=getchar(file);


*(s[i]+1)=getchar(file);


*(s[i]+2)=....and so on.....








dont know whether it will work or not coz it worked for one time and not for many times.......


No comments:

Post a Comment