it is solved
Printable View
it is solved
For the first, you need to clear the input buffer after reading your data. Search the boards. It has been asked zillions of times.
Secondly, I ask that you deduce the logic necessary. Write down the steps of your program in psuedo code, then let us see where we can go from there.
You should be familiar with the different looping structures available.
how could i "to clear the input buffer after reading your data" in this case where input always enter end the 'enter' key
i searched in the forum but cant really understand the concept~
The thing is that when you use getchar, it first asks for input, which is stored inside a input buffer.
First getchar returns the first character that was entered. Then the next. The last character in the input buffer will always be the enter character. We do not want that.
So after reading the data, clear the input buffer to get rid of the enter key stored inside there. That way you can read more data next call.
If you have read all data up to the enter key, a simply getchar() call will do to get rid of it.
sorry but where should i put the getchar()...
i am really new to C programming
As I tried to tell you in your previous thread (but I perhaps wasn't explicit enough), you shouold remove the three characters "ch=" from lines such as these:That's because you don't actually want to modify ch, you only want to print the rotated value of it.Code:printf("%d ", ch=ch>>i|ch<<(8-i));
This will also happen to fix your problem.
This is wrong. If you want to add one to i, you have a number of options:Code:i=i++;
among others. i = i++ is undefined, which means anything can happen. Practically speaking, it means you might not get the value you expect. Given the following:Code:i = i + 1;
i += 1;
i++;
I have three compilers which produce code that prints out 2, and two that print out 1. Both outputs are valid because the program's behavior is undefined.Code:#include <stdio.h>
int main(void)
{
int i = 1;
i = i++;
printf("%d\n", i);
return 0;
}