Mar 2, 2013 at 9:15pm Mar 2, 2013 at 9:15pm UTC
Write a code segment to read a list of 100 names and store it in memory. Assume each name does not contain more than 20 characters.
solution :
char N[100][20];
for(int I=0; I<=99; I++)
cin>>N[I];
is it rightt ???
or i have to right
cin >> N[i][j] ; instead of cin>>N[I];
Mar 2, 2013 at 9:35pm Mar 2, 2013 at 9:35pm UTC
I prefer using this,,,, works with spaces too
cin.getline(N[I],21);
Last edited on Mar 2, 2013 at 9:43pm Mar 2, 2013 at 9:43pm UTC
Mar 9, 2013 at 11:30pm Mar 9, 2013 at 11:30pm UTC
cin >> N[i][j];
reads in a single character, while
cin>>N[I];
reads in an array of characters. In the last case take care of the number of characters being read!