| Devilnp123 (7) | |||
So my cin gets ignored in the void "CReturn()" I don't know to solve this one... Please can someone explain that to me ? Thank u :)
| |||
|
Last edited on
|
|||
| Framework (3242) | |||
|
Please format your code with code-tags (see the "<>" button to the right when editing your post). First and foremost, you're abusing dynamic memory allocation. You only need to dynamically allocate an object if its size is large. Allocating built-in types, such as "int", "char", and "float", is unnecessary and should be placed on the stack.
Never do this. Any references to this memory will cause a segmentation-fault because you haven't allocated any memory. Instead, use "std::string" to handle any strings you have. Also, make sure you free any memory you allocate before allocating more. As for the skipping input, what are you giving as input? Wazzak | |||
|
Last edited on
|
|||
| Devilnp123 (7) | |
|
Nothing... It just skips the cin line, so I can't give an input. And then it goes further and the program closes because nothing is given. The "*c" needs to be cleared from input everytime it goes back to the beginning. Else it has the info and goes in a loop. | |
|
|
|
| Framework (3242) | |||||||
First of all, you're comparing only the first character of "choice" and nothing else. Second, 'time' has an identity crisis; it doesn't know if it's a string or a character constant. In C++, there are two ways to represent characters: a string and character constant. A character constant is a single character which is enclosed in single quotes. A string is an array of characters with a null-character at the end and are enclosed in double-quotes. Please, "std::string" is around for a reason.
See here for more: http://www.cplusplus.com/reference/string/string/ Now back to the original code. When "time" is entered as input, "time" is broken down into individual characters. When you extract data from the input stream and attempt to store the data in a "char", only one character from the input stream is extract because "char" can only hold one character at a time. After an extraction, "ime" will still remain in the input stream. Any subsequent extraction operations with "choice" will use those remaining characters as their input. Here's an example: This is the current input stream's state: Input Stream: T, I, M, E, New-Line.
'T' will be removed from the input stream and placed in "Input_". This leaves the input stream in this state: Input Stream: I, M, E, New-Line. Each extraction operation with "Input_" will extract one character from the input stream until there's not data left. If the input stream already contains data before a user enters more data, the data that's already inside the stream will be used automatically as input. See here: http://www.cplusplus.com/doc/tutorial/basic_io/ Wazzak | |||||||
|
Last edited on
|
|||||||
| Devilnp123 (7) | |
| Thanks alot man. I'm finally over that one. Up to the next mistake | |
|
|
|