1

I want a, to be read until user presses Ctrl+Z. But it does nothing. My guess is that it's visual studios fault, because when I press Ctrl+Z it shows ^Z in console. What should I do? here is my code :

#include <iostream>
using namespace std;

int main()
{
    char a[50], b[20];
    int n;
    while (1)
    {
        if (NULL == fgets(a, 50, stdin)) 
            break;
        cin >> b;
        cin >> n;
    }

    return 0;
}
AEM
  • 1,354
  • 8
  • 20
  • 30
Mohammad
  • 11
  • 2

2 Answers2

1

End of file in an interactive terminal does not depend on the language nor on the OS but on... the terminal and the configuration of the command interpretor.

If you use a true console on Windows running the good old cmd.exe, then Ctrl Z will be seen as an end of file. If you use an IDE, anything is possible and you should try also Ctrl D because some IDE prefere to provide a Unix compatible environment. After all Ctrl Z was the end of file on CP/M (ancestor of MS/DOS) in the 70'...

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
0

I tried Enter then Ctrl Z then Enter then next ... and it worked

Mohammad
  • 11
  • 2