C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 5th, 2013, 10:52 AM
CodeMonk CodeMonk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 CodeMonk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 51 sec
Reputation Power: 0
Compiler error

Hello I am going through the '"C Programming Language" book and tried this code right out of the text how ever I get this compiler error:

ll.c:6:5: error: conflicting types for ‘getline’
/usr/include/stdio.h:675:20: note: previous declaration of ‘getline’ was here
ll.c:26:7: error: conflicting types for ‘getline’
/usr/include/stdio.h:675:20: note: previous declaration of ‘getline’ was here

I can't imagine that the code in this book is wrong and it look fine to me can anyone see the mistake in this code?

// This program returns the longest line.

#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("the longest line is %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++;
}

~
~
~

Reply With Quote
  #2  
Old March 5th, 2013, 11:03 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,835 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 15 h 19 m 43 sec
Reputation Power: 1774
Code:
       #include <stdio.h>
       ssize_t getline(char **lineptr, size_t *n, FILE *stream);

getline is a POSIX standard function.

Try renaming your function to be something else.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old March 5th, 2013, 11:50 AM
CodeMonk CodeMonk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 CodeMonk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 51 sec
Reputation Power: 0
Quote:
Originally Posted by salem
Code:
       #include <stdio.h>
       ssize_t getline(char **lineptr, size_t *n, FILE *stream);

getline is a POSIX standard function.

Try renaming your function to be something else.



Thanks, that did it.
Comments on this post
clifford agrees: ... but you should not close threads just because you have an answer. Closing is to prevent posting
to threads that have degraded into unconstructive argument or abuse. Someone may have useful
insight to add - I did.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Compiler error

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap