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

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

问题描述

我想COM prehend举例1.9从K&放大器; R书,但我不明白如何发送EOF。一些消息来源提到CTR + Z,但是,简单地终止程序。我不知怎么设法与输入和Ctrl + Z,也许按Ctrl + V,但我不能复制组合发送EOF。

 的#include<&stdio.h中GT;
#定义MAXLINE 1000主要()
{
    INT LEN;
    INT最大;
    焦线[MAXLINE]
    烧焦保存[MAXLINE]    最大= 0;
    而((LEN = getline_my(线,MAXLINE))大于0)
    如果(LEN>最大){
        最大= LEN;
        复制(线,保存);
    }
    如果(最大值大于0)
        的printf(%S,保存);
}getline_my(S,LIM)
个char [];
INT LIM;
{
    INT C,I;    对于(i = 0; I< LIM-1安培;及(C =的getchar())= EOF和放大器;!&安培;!C ='\\ n';我++)//只要条件满足
        S [i] = C;
    如果(C =='\\ n'){
        S [i] = C;
        我++;
    }
    S [我] ='\\ 0';
    返回(ⅰ);
}复制(S1,S2)
S1的char [];
S2的char [];
{
    INT I;    I = 0;
    而((S2 [i] = S1 [I])!='\\ 0')
        我++;}


解决方案

您可以模拟与 EOF CTRL + D (对于* nix中)或在命令行CTRL + Z (适用于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++;

}

解决方案

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

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

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