ctrl-d appends characters to output
Matthias Apitz
guru at unixarea.de
Sat Jan 17 19:58:15 UTC 2015
El día Saturday, January 17, 2015 a las 12:59:05PM -0500, less xss escribió:
> I've searched around quite a bit with no luck on this matter. I currently
> have an issue where I send EOF (ctrl-d) to some simple K&R2 exercises and
> the terminal returns the D character appended to my data when EOF is sent.
> I wish to prevent any and all extra characters from being appended and I
> would also like to understand why it's happening. The following code
> is an example exercise from K&R2 that yield said problem.
>
> #include <stdio.h>
>
> int main() {
> double nc;
>
> for (nc = 0; getchar() != EOF; ++nc) {
> ; /* syntactic null statement */
> }
>
> printf("%.0f\n", nc);
> }
>
> $ ./a.out
> 0D
> $
This is just a display issue of your typed Ctrl-d; the '0D' is the '^D'
where the '^' is overwritten by your output of the value of 'nc';
run your a.out as:
$ ./a.out < /dev/null
or change the printf(3) line to:
printf("\n%.0f\n", nc);
HIH
matthias
--
Matthias Apitz, guru at unixarea.de, http://www.unixarea.de/ +49-170-4527211
1989-2014: The Wall was torn down so that we go to war together again.
El Muro ha sido derribado para que nos unimos en ir a la guerra otra vez.
Diese Grenze wurde aufgehoben damit wir gemeinsam wieder in den Krieg ziehen.
More information about the freebsd-hackers
mailing list