求助,对着C语言程序设计语言这本书某题打了一遍,但是却有错
#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;
}
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;
}
void copy(char to[], char from[])
{
int i;
i = 0;
while ((to[i] = from[i]) !='\0')
++i;
}
--------------------Configuration: 1-7 - Win32 Debug--------------------
Compiling...
1-7.c
D:\C\1-7.c(31) : error C2143: syntax error : missing ';' before 'type'
D:\C\1-7.c(35) : error C2065: 'i' : undeclared identifier
D:\C\1-7.c(35) : error C2065: 'lim' : undeclared identifier
D:\C\1-7.c(35) : error C2065: 'c' : undeclared identifier
D:\C\1-7.c(36) : error C2065: 's' : undeclared identifier
D:\C\1-7.c(36) : error C2109: subscript requires array or pointer type
D:\C\1-7.c(36) : error C2106: '=' : left operand must be l-value
D:\C\1-7.c(39) : error C2109: subscript requires array or pointer type
D:\C\1-7.c(39) : error C2106: '=' : left operand must be l-value
D:\C\1-7.c(42) : error C2109: subscript requires array or pointer type
D:\C\1-7.c(42) : error C2106: '=' : left operand must be l-value
Error executing cl.exe.
1-7.obj - 11 error(s), 0 warning(s)