the problem I'm having with the gets function is that it seems to already have some value pre-stored before it runs for the first time. This wouldn't normally be a problem but it messes up ma switch function.
what I've got is:
what happens is basically whenever the program goes to the screen where the switch function is present it displays the default straight away without pressing anything. Then after pressing a key the default message dissappears and the meu part comes up again.Code:char ans; int main(){ cout << "Please enter choice: "; gets(ans); switch(ans[0]){ case '1': //case 1 stuff case '2': //case 2 stuff default: cout << "Input not recognised"; waitforkeypress(); break; etc
This happens every time the screen is first displayed, whether just compiled and ran or returned to. If I use cin >> the problem is gone, but this happens in other sections of my code where whitespace characters may be present so the gets function is needed. Can someone tell me why this is?