照着书上打了一个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
mian()
{
int len; // current line length
int max; // maximum length seen so fa
char line[MAXLINE]; //current input line saved here
char longest[MAXLINE];
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 lengh
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;
}
编译时出现这样的错误。
D:\C练习\C语言\数据结构\二叉树.cpp(375) : error C2664: 'copy' : cannot convert parameter 1 from 'char [1000]' to 'char'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
执行 cl.exe 时出错.