I want to use getchar() to process a string. Here's a simplified version. I've used this code before to stop entering characters when the user enters the new-line character with no problem:
Code:
while ((c = getchar()) != '\n'){
printf("%c", c);
{
However, I prefer to read in the newline characters as part of the string. That brings to my question; I don't really understand EOF and "cntrl z". Is entering "cntrl z" in the keyboard suposed to be the same as EOF? The problem is that when the user enters "cntrl z" to simulate (or so i think) EOF, it completely exits the program. Maybe my misunderstanding is simply 'How do i simulate EOF form a windows keyboard?
This code does not do what I want because the end of the code never gets executed; it just completely exits the program when I press cntrl z. Again, is cntrl z the correct way to simulate EOF on a windows keyboard.
Code:
while ((c = getchar()) != EOF){
printf("%c", c);
{
...rest of code never gets executed