variable-named arrays

Hi! I have a problem with homework. I need to create an array for each letter from a to z. I tried to do that with loop. Looks something like that.

for (char nos='a'; nos<='z'; nos++)
{
int nos[10];
}

But it doesn't work. Obviously i don't really know how to do it, so please tell me the right way. And i would also like to know to correct way to give a variable name of char/string value.
You can't do what you're trying to do. You would have to do:

int a[10];
int b[10];
...
int z[10];

but why do you need 26 arrays anyway?
Isn't there a faster way to create a lot of arrays? Well actually I need stacks, but that doesn't really change much. I have defined stack as a class with functions push, pop, etc.

I have a txt file with some words in it, I need to put all words, that start with the same letter, in one stack(all words that start with 'a' in one stack, 'b' in next stack etc.)

So i thought I could create stack for each letter, after that i read each word as string s, and put it in the right stack like that - s[0].push(s) // s[0] would be first letter of word i have read
Make an array of stacks, like this:

Stack stack_array[26];

and then load it like this:

stack_array[str[0]-'a'].push(str);

But make sure that all words are in lower case.
Last edited on
Got it, great solution, thanks
Topic archived. No new replies allowed.