View Single Post
Old Jan 26th, 2006, 7:36 PM   #10
Jason Isom
Programmer
 
Join Date: Dec 2005
Posts: 53
Rep Power: 3 Jason Isom is on a distinguished road
Quote:
Originally Posted by cwl157
ok i apologize. I should have made this clear in the beginning but i can't use classes to make this program. I can only use structs and subroutines.
Can you use std::string? Or do you have to use char arrays? If you have to use char arrays, can department code be more than one character?

Because...

Quote:
Originally Posted by Jason Isom
Anyhow, to the original poster. The reason your print function isn't printing out everything is because you must set "i = 0" in the print function. You have a global variable (which is generally a bad idea) that is incremented up to loc, but it's never set back to the beginning.

There are other issues however. Department code can only be one character, because you've declared "department" to be 2 characters, but one of those characters is going to be occupied by \0 because you're using a char* string. You should probably stick to std::string if you're using C++, unless of course
your professor does not allow it.
You're using std::cin for input into a character array without any thought about how many characters a user will type. If they type more than 1 (because you're using char department[2]) it will actually cause a out of bounds error. When you std::cout the department, it will actually keep printing random stuff until it encounters a null-terminating character (\0). They occur often enough on disk that your program won't crash every single time, but you definitely should look into a version of getline. At least I think getline is what you're looking for.
Jason Isom is offline   Reply With Quote