我是C新手,我使用的是C編程語言,我抄下1.9試圖打印最長的一行。雖然我嘗試在Xcode中構建程序,但它顯示出存在類型衝突和表達問題的錯誤,但我仍試圖將函數「getline」放在main之前,但我仍然不知道發生了什麼問題。The C Programming Language 1.9
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line size */
int getline(char line[ ], int marline); ----ISSUE:Conflicting types for "getline"
void copy(char to[ ], char from[ ]);
/* print longest input line*/
int main(){
int len; /* current line length */
int max; /* maximum length seen so far */
char line[MAXLINE]; /*current input line*/
char longest[MAXLINE]; /* longest line saved here */
max=0;
while ((len=getline(line[ ], MAXLINE))>0) ------ISSUE:Expected Expression
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 length */
int getline(char s[ ], int lim){ ----ISSUE:Conflicting types for "getline"
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;}
請正確格式化您的代碼。 –
[getline](http://man7.org/linux/man-pages/man3/getdelim.3.html)是保留函數。 ((len = getline(line,MAXLINE))> 0)'重命名該函數,例如:'my_getline' – LPs
'while((len = getline(line [],MAXLINE))> 0)' - >'。其餘的,請參閱下面的答案。 –