0

SO in linux i could probably end a while-loop with this kind of code if I compile with gcc:

#include <stdio.h>

int main()
{   
    int s;
    while(scanf("d%",&s)!=EOF);
    {   
        scanf("%d",&s);
          }
    return 0;
}

However this does not work with a windows computer and the compiler Im using is Microsoft Visual Studio 12. Any suggestions?

Jask
  • 650
  • 10
  • 23
Tensora
  • 59
  • 8

2 Answers2

2
#include <stdio.h>

int main() {
    int s;
    while((s = getchar()) != EOF) {
        printf("%d\n", s);
    }
    printf("%d - at EOF\n", s);
}

you can try this

Ferrakkem Bhuiyan
  • 2,577
  • 1
  • 18
  • 35
  • Just a question on this, if I want to print something in the whileloop before the user gets to input data, how could I do then? because now it prompts the user the first thing it does in the program? – Tensora Feb 16 '14 at 20:29
1

Try it with strg + c or strg + z. I think that was which overgives the EOF

user3202845
  • 41
  • 1
  • 7