如何通过 Windows 终端发送 EOF [英] How to send EOF via Windows terminal

查看:22
本文介绍了如何通过 Windows 终端发送 EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解 K&R 书中的示例 1.9,但我不知道如何发送 EOF.一些消息来源提到了 Ctr+Z,但这只是终止了程序.我以某种方式设法通过 Enter 和 Ctrl+Z 以及 Ctrl+V 的组合发送 EOF,但我无法重现它.

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 != '
'; i++)// As long as the condition is fulfilled
        s[i] = c;
    if (c == '
') {
        s[i] = c;
        i++;
    }
    s[i] = '';
    return(i);
}

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

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

}

推荐答案

您可以使用 CTRL+D(对于 *nix)或 CTRL+Z(对于Windows)从命令行.

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

这篇关于如何通过 Windows 终端发送 EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆