Strange things with output
Kinda simle code:
1 2 3 4 5 6 7
|
int main (){
char c;
while ((c=getchar())!='\n') {
cout <<c<<endl;
}
return 0;
}
|
After run it gives me the follow:
1 2 3 4 5 6
|
roman@admin:~/Documents/c/newtry$ ./a.out
Test
T
e
s
t
|
and this right )
but if i want to print all at one string:
1 2 3 4 5 6 7
|
int main (){
char c;
while ((c=getchar())!='\n') {
cout <<c; //deleted <<endl here
}
return 0;
}
|
it gives me that:
1 2 3
|
roman@admin:~/Documents/c/newtry$ ./a.out
Test
roman@admin:~/Documents/c/newtry$ ry$
|
What's wrong? Thanks at advance.
Really? It works fine for me.
both code? with and w/o <<endl ?
Weird.
Anyway, pay attention here:
1 2
|
char c;
while ((c=getchar())!='\n')
|
getchar() returns an integer, not a char. It does so because the EOF macro needs to be different from every other valid char.
thanks a lot, try with c as int and EOF works fine!
Topic archived. No new replies allowed.