Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send EOF via Windows terminal

Tags:

c

windows

I'm trying to comprehend Example 1.9 from the K&R book, but I don't get how to send EOF. Some sources mentioned Ctr+Z, but that simply terminates the program. I somehow managed to send EOF with a combination of Enter and Ctrl+Z and maybe Ctrl+V, but I can't reproduce it.

#include <stdio.h>
#define MAXLINE 1000

main()
{
    int len;
    int max;
    char line[MAXLINE];
    char save[MAXLINE];

    max = 0;
    while((len = getline_my(line, MAXLINE)) > 0)
    if(len > max) {
        max = len;
        copy(line, save);
    }
    if(max > 0)
        printf("%s", save);
}

getline_my(s, lim)
char s[];
int lim;
{
    int c, i;

    for(i=0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; i++)// As long as the condition is fulfilled
        s[i] = c;
    if (c == '\n') {
        s[i] = c;
        i++;
    }
    s[i] = '\0';
    return(i);
}

copy(s1, s2)
char s1[];
char s2[];
{
    int i;

    i = 0;
    while((s2[i] = s1[i]) != '\0')
        i++;

}
like image 962
804b18f832fb419fb142 Avatar asked Apr 21 '13 21:04

804b18f832fb419fb142


People also ask

How do I pass EOF in terminal?

the “end-of-file” (EOF) key combination can be used to quickly log out of any terminal. CTRL-D is also used in programs such as “at” to signal that you have finished typing your commands (the EOF command). key combination is used to stop a process. It can be used to put something in the background temporarily.

How do you send an EOF signal?

eof is not a signal but is implemented by the tty driver as a read of length 0 when you type ctrl-d .

How do I type EOF characters?

The EOF in C/Linux is control^d on your keyboard; that is, you hold down the control key and hit d. The ascii value for EOF (CTRL-D) is 0x05 as shown in this ascii table . Typically a text file will have text and a bunch of whitespaces (e.g., blanks, tabs, spaces, newline characters) and terminate with an EOF.

What is the EOF character in Windows?

Introduction. In Linux and MacOS environments, you can terminate standard input by outputting EOF (end of file) using the CTRL-D keyboard shortcut. In Windows, the CTRL-D key combination does not do the same.


2 Answers

You can simulate EOF with CTRL+D (for *nix) or CTRL+Z then Enter (for Windows) from command line.

like image 113
xagyg Avatar answered Oct 06 '22 15:10

xagyg


In widows, when you are ready to complete the input, press the Enter key and then press Ctrl+Z and then Enter to complete the input.

int main(){
    char ch[100];    
    scanf("%[^EOF]",ch);    
    printf("\nthe string is:\n%s\n",ch);    
    fflush(stdin);    
    return 0;    
    }
like image 26
mauriceShun Avatar answered Oct 06 '22 15:10

mauriceShun