操作系统:rhel6
编译环境:gcc-4.4.4
源代码如下:
- #include "stdio.h"
- #define MAXLEN 1000 /*maximum characters of input length line*/
- /*从输入的信息行内,找出最长的行,并且输出*/
- main()
- {
- int getline(char cur__line[],int max);
- void copy(char max_line[],char cur_line[]);
- int len,max;
- char cur_line[MAXLEN]; /*save the current lines*/
- char max_line[MAXLEN]; /*save the max maximum lines*/
-
- len=max=0;
- while((len=getline(cur_line,MAXLEN))>0)
- if(len>max){
- max=len;
- copy(max_line,cur_line);
- }
- if(max>0) /*this line is exist*/
- printf("%s",max_line);
- return 0;
- }
- /*read a line into cur_line; return length*/
- int getline(char cur_line[],int max)
- {
- int ch,count;
- printf("input a few lines:\n");
- for(count=0;count<max-1 && (ch=getchar())!='$' && ch!='\n';count++)
- *(cur_line+count)=ch;
- if(ch=='\n'){
- *(cur_line+count)=ch;
- count++;
- }
- *(cur_line+count)='\0';
- return count;
- }
- /*copy: copy 'from' into 'to' ;assume to is big enough*/
- void copy(char to[],char from[])
- {
- int count;
-
- for(count=0;(*(to+count)=*(from+count))!='\0';count++)
- ;
- }
报错如下:
Press ENTER or type command to continue
读入文本行并输出最长行.c:7: error: conflicting types for ‘getline’
/usr/include/stdio.h:673: note: previous declaration of ‘getline’ was here
读入文本行并输出最长行.c:29: error: conflicting types for ‘getline’
/usr/include/stdio.h:673: note: previous declaration of ‘getline’ was here
报错原因:
在studio.h头文件内,已经包含了getline函数,而我们又重新定义了一个getline函数,所以会提示定义的函数冲突
处理方案:
将我们自己定义的函数改个名字,如get_line(),问题解决
阅读(4520) | 评论(0) | 转发(0) |