-1

How can I input in C language at EOF?

I just want to know the process. I will be very thankful if someone elaborate it by example.

prokawsar
  • 150
  • 1
  • 15
  • 2
    CRTL+D on linux for `scanf()` and family, replace D with Z on windows – Sourav Ghosh Jul 28 '15 at 09:33
  • 1
    or use the above username. :P – Sourav Ghosh Jul 28 '15 at 09:34
  • if you are solving online judge problem and the problem specifies that input will be terminated by `EOF` then you can simply take the input in while argument like `while( scanf("%d", &n ))`. On success, `scanf()` returns the number of items of the argument list successfully filled. so when it gets `EOF`, it will return `0` and the `while` loop will break. – Rafaf Tahsin Jul 28 '15 at 10:15
  • Yes You got it. With getting input I have to print its result, so ? I have tried this : `while( scanf("%d %d", &a, &b));{ printf("%d\n", b-a); }` but it seems wrong – prokawsar Jul 28 '15 at 10:23

1 Answers1

1

You can have EOF with CTRL+D (for unix) or CTRL+Z (for Windows) from command line.

user2736738
  • 30,591
  • 5
  • 42
  • 56