I have trouble finishing a while loop using '\0'
in c programming language, the c code is the following
#include<stdio.h>
char r;
int main()
{
do
{
scanf("%c", &r );
printf("%c", r);
}
while (r!='\0');
return 0;
}
My problem is that the program never finishes at the final character of typed string line, the while loop is always in waiting mode because of the scanf
and never go to return 0
. I do not know why this happen.
The output of this program is like this:
1234
2345
4556
7788
2345, 4556, 7788
Those are numbers I typed, but the program never finish (never go to return 0
), I want to print just one string and I want the program ends.