Hi, this is a simple temperature converter (Fahrenheit to Celsius to Kelvin). Using gcc 4.0. The user is supposed to enter q or any other non-character to exit the program. Problem with this code: I enter 'q' as soon as the program starts. It hangs. Then run it again. Enter a number, it executes fine. But when I enter q, it ...
I thought I would use a do-while because it always loops once anyway After a numberic value is entered I thought it would prompt for the char entry. But it is falling all the the way thru; failing and asking a second time giving the correct results. I would like it to stop on the first go round and get the ...
When scanf() pulls in a char, it leaves a newline char behind. It does the same thing for numbers. Whitespace, like newline char's, are skipped over by scanf(), when it's looking for a number for input. For char's, scanf() will not skip over a newline char - it will accept the newline as valid input, and make your program act nutty. ...
I tried using a while loop with a switch statement. I had a char as the decision element .. the program compiled correctly but in operation the while loop was looping too often. I tried a different approach still using a char as the decision element and got other problems. however when I finally decided to try using ints as the ...
Code: void playgame() { char answer; int x = 0; while ( x == 0){ printf( "Maybe we can play a guessing game instead? Y or N\n"); getchar(); scanf( "%c", &answer ); if ( (answer == 121) || (answer == 89) ) { printf( "Ok, but you will surely give up before you win!\n" ); x = 1; } else if ...
What am I doing wrong here? I've tried this in the main, I've tried it in a function using a return statement, and here is my attempt to pass a pointer to a character (a math operator--this is supposed to be a calculator program) into a loop. It goes in the first time, but then after that it ignores the input ...
That's because you enter at least two characters when you enter an option. For example: c The scanf() will read the letter 'c' and leave the \n in the input buffer waiting to be processed later. The next time around, the scanf() function will read the \n character which was left behind. You can probably guess how to remove the \n ...
Here is what I have, and I cant see why it isnt working. User enters a sentence, and my function is to remove the whitespace from what user entered. void whitespace(char str[]) { int i; for(i=0; i!='\0'; i++) while(isspace(str[i])) { str[i] = str[i+1]; } } Any suggestions as to why this isnt working? I am not getting any errors.....