//timed message function
int timed_message(char message [], bool use_seconds, int time)
{
for(int x=0; x<=/*SIZE OF MESSAGE ARRAY*/;++x)
{
cout << message[x];
}
}
int main()
{
timed_message("This message will appear at a steady rate.", false, 100);
//keep the console open and exit
cin.get();
return EXIT_SUCCESS;
}
I need that for loop to only run while there are still characters in the char array. Otherwise it will print some weird crap and freak the program out.
How would I work Tevsky's solution into my function as a parameter?
Ah I'm a fool, I didn't read the "function parameter" part in your first post, and then didn't put two and two together when Helios mentioned "pass as a parameter". Helios is correct, you can't, you have to pass the size as a parameter. My solution only works when you have direct access to the array. You could always get rid of the function, load that message into a char array, and then put the loop in main and use the thing I suggested.
Or simply, use a string. The two of these things are only if you must have access to the individual chars though.
I have two questions:
1. Why didn't you say you were passing a C string (a char array may or may not be a C string)?
2. What's wrong with std::cout <<message;?
1. I've had a headache all day, not really thinking clearly and forgot the name. :P
2. Well there's much more to the timed_message function, what it does is show the characters in the array, err.. C String, one by one, and plays a keyboard typing sound, as if someone is typing the letters onto the screen.
It's only a function because I plan to use this many times in the game I am developing. (It's a text based RPG.)
You can print the letters one by one with a string?
You can, exactly the same way as with a char array. Here's your code with a string, all I did was change the parameter from char array to a string. And then I put in the method message.size() as the loop condition. This function returns how many characters are in the string.