红联Linux门户
Linux帮助

求助高人 parse error at end of input

发布时间:2010-01-19 11:02:44来源:红联作者:longyu1985
用GCC编译,程序源代码只有84行,但是在编译的时候却在85行出现这样的错误:parse error at end of input。
小弟刚刚入门,请高人指点,我的邮箱:[email=longyuping1985@126.com]longyuping1985@126.com[/email]
以下是源代码:
#include
#define MAXLINE 1000 /* maximum input line size */

int geline(char line[], int maxline);
void copy(char to[], char from[]);

/* print 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]; /* save the longest line current */

max = 0;
while ((len = getline(line, MAXLINE)) >= 0) {
printf("%d, %s", len, line);
if (len > max) { /* select the max line */
max = len;
copy(longest, line);
}
}

/* getline: read a line into s, return length.................*/
int getline(char s[], int lim)
{
int c, i, j;

j = 0;
for (i = 0; (c = getchar()) != '?' && c != '\n'; ++i)
if (i < lim - 2) {
s[j] = c; /* line still in boundaries */
++j;
}
if ( c = '\n') {
s[j] = c;
++j;
++i;
}
s[j] = '\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 = from[i]) != '\0')
++i;
}
[/i]
文章评论

共有 2 条评论

  1. longyu1985 于 2010-01-19 11:08:12发表:

    2# longyu1985
    最好那里是:while ((to[i] = from[i]) != '\0')

  2. longyu1985 于 2010-01-19 11:04:32发表:

    1# longyu1985
    源代码:#include
    #define MAXLINE 1000 /* maximum input line size */
    int geline(char line[], int maxline);
    void copy(char to[], char from[]);
    /* print 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]; /* save the longest line current */
    max = 0;
    while ((len = getline(line, MAXLINE)) >= 0) {
    printf("%d, %s", len, line);
    if (len > max) { /* select the max line */
    max = len;
    copy(longest, line);
    }
    }
    /* getline: read a line into s, return length.................*/
    int getline(char s[], int lim)
    {
    int c, i, j;

    j = 0;
    for (i = 0; (c = getchar()) != '?' && c != '\n'; ++i)
    if (i < lim - 2) {
    s[j] = c; /* line still in boundaries */
    ++j;
    }
    if ( c = '\n') {
    s[j] = c;
    ++j;
    ++i;
    }
    s[j] = '\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;
    }