c语言问题.

#include <stdio.h>
#define MAXLINE 1000 /* maximum input line length */
int getline(char line[], int maxline);
void copy(char to[], char from[]);
/* print the longest input line */
main()
{
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXLINE]; /* current input line */
char longest[MAXLINE]; /* longest line saved here */
max = 0;
while ((len = getline(line, MAXLINE)) > 0)
if (len > max) {
max = len;
copy(longest, line);
}
if (max > 0) /* there was a line */
printf("%s", longest);
return 0;
}
/* getline: read a line into s, return length */
int getline(char s[],int lim)
{
int c, i;
for(i=0; i < lim-1&& (c=getchar())!=EOF && c!='\n'; ++i)
s[i] = c;
if (c == '\n') {
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
/* copy: copy 'from' into 'to'; assume to is big enough */
void copy(char to[], char from[])
{
int i;
i = 0;
while ((to[i] = from[i]) != '\0')
++i;
}
这个程序是什么意思.
怎样输入才会有输出.

#include <stdio.h>
#define MAXLINE 1000 /* maximum input line length */
int getline(char line[], int maxline);
void copy(char to[], char from[]);
/* print the longest input line */
int main()
{
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXLINE]; /* current input line */
char longest[MAXLINE]; /* longest line saved here */
max = 0;
if ((len = getline(line, MAXLINE)) > 0)
if (len > max) {
max = len;
copy(longest, line);
}
if (max > 0) /* there was a line */
printf("%s", longest);
return 0;
}
/* getline: read a line into s, return length */
int getline(char s[],int lim)
{
int c, i;
for(i=0; i < lim-1&& (c=getchar())!=EOF && c!='\n'; ++i)
s[i] = c;
if (c == '\n') {
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
/* copy: copy 'from' into 'to'; assume to is big enough */
void copy(char to[], char from[])
{
int i;
i = 0;
while ((to[i] = from[i]) != '\0')
++i;
}
我想这个程序应该是实现对输入字符串的复制功能,在屏幕上输入一段少于1000个字符的字符串,第二行就输出复制的字符串。原来函数中的while用的不对,这样将会永远输入结束不了,所以也看不到复制功能,改为if就好了
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-04-12
没有缩进,看来比较累

但是输入一串字符以后要输入结束标志EOF表示你的输入结束了

如果你是Unix,就用Ctrl+D,DOS就用Ctrl+Z本回答被提问者采纳
第2个回答  2012-04-11
输入一个字符串,然后复制到longest数组,再将其输出,不知有何意义。
第3个回答  2012-04-12
路过!!!!!!!!!!!!!!!
相似回答