标题:请大家帮忙看看需要怎么改才对
只看楼主
freedgun
Rank: 5Rank: 5
等 级:职业侠客
帖 子:147
专家分:302
注 册:2010-11-11
结帖率:100%
已结贴  问题点数:10 回复次数:2 
请大家帮忙看看需要怎么改才对
#include<stdio.h>
int  getline(void);
void copy(void);

/* print longest input line; specialized version */
main()
{
    int len;
    extern int max;
    extern char longest[];

    max = 0;
    while ((len = getline()) > 0)
        if(len > max) {
            max = len;
            copy();
        }
        if (max > 0)  /* there was a line */
            printf ("%s", longest);
        return 0;
}

/* getline: specialized version */
int getline(void)
{
    int c, i;
    extern char line[];
    for (i = 0; i < MAXLINE - 1
        && (c=getchar) != EOF && c != '\n'; ++i)
        line[i] = c;
    if (c == '\n') {
        line[i] = c;
        ++i;
    }
    line[i] = '\0';
    return i;
}

/* copy: specialized version */
void copy(void)
{
    int i;
    extern char line[],longest[];

    i = 0;
    while ((longest[i] = line[i]) != '\0')
        ++i;
}
搜索更多相关主题的帖子: version include return 
2010-11-18 19:50
xiaomarn
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:5
帖 子:348
专家分:2026
注 册:2009-3-18
得分:10 
程序代码:
#include<stdio.h>
int  getline(void);
void copy(void);

#define MAXLINE 128

char longest[MAXLINE];
char line[MAXLINE];


/* print longest input line; specialized version */
int
main()
{
    int len;
    int max;

    max = 0;
    while ((len = getline()) > 1)
        if(len > max) {
            max = len;
            copy();
        }
        if (max > 0)  /* there was a line */
            printf ("%s", longest);
        getch();
        return 0;
}

/* getline: specialized version */
int getline(void)
{
    int c, i;

    for (i = 0; i < MAXLINE - 1
        && (c=getchar()) != EOF && c != '\n'; ++i)
        line[i] = c;
    if (c == '\n') {
        line[i] = c;
        ++i;
    }
    line[i] = '\0';
    return i;
}

/* copy: specialized version */
void copy(void)
{
    int i;

    i = 0;
    while ((longest[i] = line[i]) != '\0')
        ++i;
}

2010-11-18 21:15
freedgun
Rank: 5Rank: 5
等 级:职业侠客
帖 子:147
专家分:302
注 册:2010-11-11
得分:0 
回复 2楼 xiaomarn
很感谢

有什么样的付出,就有什么样的收获!!
2010-11-18 21:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-326163-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015233 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved