Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > getline() problem

Reply
Thread Tools

getline() problem

 
 
arnuld
Guest
Posts: n/a
 
      04-21-2008
I am learning malloc() and realloc() and I got the code from here:

http://www.eskimo.com/~scs/cclass/notes/sx11c.html


#include <stdio.h>
#include <stdlib.h>


enum MAXSIZE { ARRSIZE = 1000 };


int main( void )
{
char line_of_chars[ARRSIZE];
int *ip;
int nallocs, nitems;

nallocs = 100;
ip = malloc(nallocs * sizeof( int ));

if( ip == NULL )
{
fprintf( stderr, "out of memory\n");
exit(EXIT_FAILURE);
}



nitems = 0;
while( getline(line_of_chars, ARRSIZE) != EOF)
{
if( nitems >= nallocs )
{
int *newp;
nallocs += 100;
newp = realloc( ip, nallocs * sizeof(int));

if( newp == NULL )
{
fprintf( stderr, "out of memory\n");
exit(EXIT_FAILURE);
}

ip = newp;
}

ip[nitems++] = atoi(line_of_chars);
}


return EXIT_SUCCESS;
}


I am keep on getting this warnings when I try to compile this function:


/home/arnuld/programs/C $ gcc -ansi -pedantic -Wall -Wextra eskimo.c
eskimo.c: In function `main':
eskimo.c:30: warning: implicit declaration of function `getline'
/home/arnuld/programs/C $



from here I see that getline() is defined in <stdio.h>:

http://crasseux.com/books/ctutorial/getline.html


then why I am getting the warning ?



--
http://lispmachine.wordpress.com/
my email ID is at the above address

 
Reply With Quote
 
 
 
 
arnuld
Guest
Posts: n/a
 
      04-21-2008
> On Mon, 21 Apr 2008 10:41:34 +0500, arnuld wrote:


> from here I see that getline() is defined in <stdio.h>:
>
> http://crasseux.com/books/ctutorial/getline.html



sorry, I meant this:
http://www.gnu.org/software/libtool/...ine-Input.html




--
http://lispmachine.wordpress.com/
my email ID is at the above address

 
Reply With Quote
 
 
 
 
arnuld
Guest
Posts: n/a
 
      04-21-2008
On Mon, 21 Apr 2008 10:41:34 +0500, arnuld wrote:

> I am learning malloc() and realloc() and I got the code from here:


> ...[SNIP].....


> http://www.eskimo.com/~scs/cclass/notes/sx11c.html
> from here I see that getline() is defined in <stdio.h>:



Oh.. no, searching the archives I found that "Ben Pfaff" says that
getline() is not a standard C function:

http://groups.google.com/group/comp....1d4f43fd4b2f8b





--
http://lispmachine.wordpress.com/
my email ID is at the above address

 
Reply With Quote
 
WANG Cong
Guest
Posts: n/a
 
      04-21-2008
arnuld wrote:

> On Mon, 21 Apr 2008 10:41:34 +0500, arnuld wrote:
>
>> I am learning malloc() and realloc() and I got the code from here:

>
>> ...[SNIP].....

>
>> http://www.eskimo.com/~scs/cclass/notes/sx11c.html
>> from here I see that getline() is defined in <stdio.h>:

>
>
> Oh.. no, searching the archives I found that "Ben Pfaff" says that
> getline() is not a standard C function:


<snip>

True. getline() is a GNU extension. If you want to use it, you must
define the macro _GNU_SOURCE before including <stdio.h>.

--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      04-21-2008
WANG Cong wrote, On 21/04/08 07:21:
> arnuld wrote:
>
>> On Mon, 21 Apr 2008 10:41:34 +0500, arnuld wrote:
>>
>>> I am learning malloc() and realloc() and I got the code from here:
>>> ...[SNIP].....
>>> http://www.eskimo.com/~scs/cclass/notes/sx11c.html
>>> from here I see that getline() is defined in <stdio.h>:

>>
>> Oh.. no, searching the archives I found that "Ben Pfaff" says that
>> getline() is not a standard C function:

>
> <snip>
>
> True. getline() is a GNU extension. If you want to use it, you must
> define the macro _GNU_SOURCE before including <stdio.h>.


This is unlikely to help arnuld as that is not the getline function he
is looking for. The one arnuld is looking for is in an earlier chapter
of the notes where the full source for it is provided.
--
Flash Gordon
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments