In the future, please tell us what you expect to see, not just "this isn't what I want." Having said that, let's step through your code.
#include <stdio.h>
void main(void)
The language standard mandates that main()
return an int. This may not prevent your code from compiling, but more and more compilers are starting to issue warnings about main()
not being typed int, and there are some (uncommon) platforms where using void main()
may result in runtime problems. Unless your compiler documentation specifically says, "yes, we support void main()
," use int main(void)
or int main(int argc, char **argv)
.
{
int i;
char c;
for (i=0;i <5;i++)
{
scanf("%d",&c);
You're confusing scanf()
: a %d
conversion specifier expects its corresponding argument to be a pointer to int, but you're passing a pointer to char. Either change the type of c to an int (recommended), or use a %c
conversion specifier (but then you have to worry about handling whitespace, so it's probably better to just type c as int).
printf("i=%d\r\n",i);
Why are you bothering to read c if you're not going to print it out? Secondly, \n
should be sufficient to write a newline; you don't need the \r
.
}
printf("The loop is finished!\r\n");
Same comment as above re: \r
.
}