I'm new to code, and i am trying to do a program with arrays. I'm starting with imputing characters into an array, and then i try to transfer those characters into an multidirectional array(if thats what you call it).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
int main (){
char imputarray[10];
cout << "letters seperated by spaces:" << endl;
cin >> imputarray;
char mainarray[10][100];
int n = -1;
while(n>10) {n++;
mainarray[n][0] = imputarray[n];
}
cout << mainarray[1][0] << endl;}
when i try to test and see if it transfered by displaying one of the characters, it only returns whitespace. Why is that happening?
p.s. if anyone can tell me how to input characters into a multidirectional array, that would make my life a whole lot easier.
im having a hard time explaining what's happening, but the problem is still the same. are you running these programs yourself? if not, can you? its probably a very simple problem but i dont know how to explain what that problem is
I am sorry I don't understand what you want--yes I did run the above program and it worked as I expected. I would suggest that you read the link I posted above it is very simple but it explains arrays quite well.
I just ran the program, and i realized what was wrong. it only runs the program once 10 characters have been entered. how do you fix that? i want to be able to enter any series of characters that is ten or less in length and press enter and assign those values to imput array.
#include <iostream>
usingnamespace std;
int main ()
{
char imputarray[10];
cout << "letters seperated by spaces:" << endl;
char c;
unsigned i = 0;
while(i != 10) {
cin.get(c);
if( c == '\n')break;
elseif (isspace(c));
else imputarray[i++] = c;
}
cout << "show that imputarray is populated\n";
for(unsigned j = 0; j != i; j++) cout << imputarray[j]<< ' ';
cout << endl;
char mainarray[10][100];
int n = -1 ;
while(n<10) {
n++;
mainarray[n][0] = imputarray[n];
}
cout << "show that mainarray has been populated:\n";
for(unsigned j = 0; j != i; j ++)
cout << mainarray[j][0] << ' ';
cout << endl;
return 0;
}
I am sure this doesn't work as expected either because it will accept characters entered without spaces...but at least you may have something to work with--modify and make work the way you want.