Last edited by supradriver; 04-27-2009 at 04:49 PM.
#1. main should return an int.
I somehow doubt a getrand function returns a char, and if it does that is not the way to declare a function - or is it something else. Where is the code for the function, what is it supposed to do?Code:char getrand;
Your noun/verb/article/preposition functions do nothing other than allocate space for a local array which is immediately thrown away once the functions end. At the very least you'd need to be passing something into or out of the functions or returning something or setting a global variable within the functions to get anything happening after a call. It seems - in theory - that you'd either want to pass the index returned from the getrand function call into the function and return a char pointer to one a word in the array, or you'd call getrand locally in each noun/verb/preposition/article function and again use that to return a char pointer to one of the words. In either case, if you insist on using functions for these, this should be done with the arrays declared as static. I'd probably simply go with all these array declared locally in main for such a simple program and forego the use of functions for that purpose.
I'm guessing you need to call the "getrand" function once for each noun/article/verb/preposition that you wish the final sentence to contain. The argument to getrand, if any, is probably a range of values 0-N where N is one minus the number of array values you are trying to index into (which could theoretically be different for each class of noun/verb, etc...). You then need to set individual char pointers (not simple chars) according to the indexed words and then print out sentence using the char pointers (%s, not %c).
And since this is the C++ board, you should probably consider std::strings and C++ I/O streams instead of char arrays and printf... unless you're constrained in that manner.[/edit]
Last edited by hk_mp5kpdw; 04-27-2009 at 04:16 PM.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."