代码拉取完成,页面将自动刷新
#include <stdio.h>
#define MAXLINE 1000 /* 允许的输入行的最大长度 */
int getline(char line[], int maxline);
void copy(char to[], char from[]);
/* 打印最长的输入行 */
main()
{
int len; /* 当前行长度 */
int max; /* 目前为止发现的最长行的长度 */
char line[MAXLINE]; /* 当前的输入行 */
char longest[MAXLINE]; /* 用于保存最长的行 */
max = 0;
while ((len = getline(line,MAXLINE)) > 0)
if (len > max){
max = len;
copy(longest,line);
}
if (max > 0) /* 存在这样的行 */
printf("%s",longest);
return 0;
}
/* getline函数:将一行读入到s中并返回其长度 */
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函数:将from复制到to;这里假定to够大 */
void copy(char to[], char from[])
{
int i;
i = 0;
while ((to[i] = from[i]) != '\0')
++i;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。