Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C newbie questions?

Name: Anonymous 2013-09-30 11:14

ive been trying to learn c. in this program and a few others the app waits for EOF and i dunno how to send EOF on a terminal to make it work. i tried ^C and "." help plz?
#include <stdio.h>
/* count lines in input */

main()
{

    int c, nl;
    nl = 0;
    while ((c = getchar()) != EOF)
        if (c == '\n')
            ++nl;
    printf("%d\n", nl);
}

Name: Anonymous 2013-09-30 12:59

If it ain't LISP, it's shit. Commit suicide.

Name: Anonymous 2013-09-30 13:15

fine then, how do you type in end of file into a running lisp program. it's surely the same.

Name: Anonymous 2013-09-30 13:22

Name: Anonymous 2013-09-30 13:52

>>1
Ctrl-Z

>>2
If it ain't LISP, it's shit. Commit suicide.
But LISP is dead.
And C is faster.

Name: Anonymous 2013-09-30 14:00

^Z is suspend. it just pauses an app.

Name: Namefag 2013-09-30 14:06

C is pretty much anus. Use pythons.

Name: Anonymous 2013-09-30 14:57

(call-with-input-file "a.txt"
  (lambda (input-port)
    (let loop ((x (read-char input-port)))
      (if (not (eof-object? x))
          (begin
            (display x)
            (loop (read-char input-port)))))))
Taken from StackOverflow, a place full of helpful people and answers. If you're struggling with something, StackOverflow is probably your best bet. And now that the StackExchange network has expanded so greatly, there are Q&A resources for almost every topic imaginable!

Name: Anonymous 2013-09-30 15:21

thanks, i found it on stackoverflow. eof is ^z for ms-dos and ^D for windows. the app worked perfectly after that.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List