我正在尝试从K&R书中理解Example 1.9,但是我不知道如何发送EOF。一些消息来源提到Ctr + Z,但这只是终止程序。我设法以Enter和Ctrl + Z以及Ctrl + V的组合发送了EOF,但是我无法重现它。#include <stdio.h>#define MAXLINE 1000main(){ 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++;}
- 3 回答
- 0 关注
- 788 浏览
添加回答
举报
0/150
提交
取消