String array's? How can you???

This is a discussion on String array's? How can you??? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I'm working on a database program and I'm using array's to store the names entered into the program but seeing ...

String array's? How can you???

I'm working on a database program and I'm using array's to store the names entered into the program but seeing that Strings are already char arrays, it's become quite difficult. I'm having problems using 2 dimensional arrays to do this. Can anyone help? Here's the commented code, it's not too long. Thanks!

>>char nameInSlot[ARRAY_MAX][i];
How big is i when this variable is declared? Answer: 0. Therefore, you've created an array like so:
nameInSlot[ARRAY_MAX][0];
Also, using variables within an array declaration is allowed (unless you're using C99 standard compiler). The array sizes have to be known at compile time.

>>nameInSlot[ARRAY_MAX][i] = name[ARRAY_MAX];
This does not copy a string, to do that you need strcpy().

Here's an adapted version to show you the way forward. It isn't by any means complete, but it should get your going in the right direction.

Thanks a lot, I'll be sure to make note of doing it that way! I actually figured a way how to do it with structures (arraying the structure string) after a little bit of posting this thread, which took up more space than you way. Unfortunatly I couldn't get back to the web site (Was it down??) to say I figured it out... (kept getting a DNS error).

Anyway, why is "fflush"ing the stdin after a scanf not good? I always thought you had to fflush your input after you used a scanf? (or fscanf) and why do you fflush the stdout after your printf? I read the page you linked to but it didn't really clear it up completely for me.... I didn't really see anything they flushed the input with.. the closest I saw was the "cout.flush()". (personally, I'm not a fan of "cin" and "cout"... it takes up too much room, well atleast the cout). ????????????????????????