i am using mac,Xcode to run the very simple code as below, but it shows nothing? why? did i miss anything? would it be different if i run it with other machine or other compiler?
int main ()
{
double nc;
for (nc=0; getchar() !=EOF; ++nc)
//printf("%.0f\n", nc)
;
int main ()
{
double nc;
for (nc=0; getchar() !=EOF; ++nc)
printf("%.0f\n", nc)
;
//printf("%.0f\n", nc);
}
the put in "oooo"
i will have result of below
0
1
2
3
4
my understanding is the second program count letters one by one, i would expect the first program just give me one final result, that is "4" if i type in "oooo". .....
but it shows nothing...
int main ()
{
double nc;
for (nc=0; getchar() !=EOF; ++nc)
printf("%.0f\n", nc);
printf("foo");//and add this line here.
}
If you can somehow get "foo" printed (without changing the code), everything is great. If not, it means that the condition always returns true and is thus broken.
When you come to that realisation, you have to ask yourself what kind of condition you want. If it's to go until the end of line, replace EOF with '\n'.