getline() problem

Discussion in 'C Programming' started by arnuld, Apr 21, 2008.

  1. arnuld

    arnuld Guest

    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
    arnuld, Apr 21, 2008
    #1
    1. Advertising

  2. arnuld

    arnuld Guest

    arnuld, Apr 21, 2008
    #2
    1. Advertising

  3. arnuld

    arnuld Guest

    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...43fd4b2f8b?lnk=gst&q=getline#c21d4f43fd4b2f8b





    --
    http://lispmachine.wordpress.com/
    my email ID is at the above address
    arnuld, Apr 21, 2008
    #3
  4. arnuld

    WANG Cong Guest

    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.
    WANG Cong, Apr 21, 2008
    #4
  5. arnuld

    Flash Gordon Guest

    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
    Flash Gordon, Apr 21, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John
    Replies:
    10
    Views:
    10,034
    Buster Copley
    Jul 14, 2003
  2. Poof
    Replies:
    1
    Views:
    374
  3. Joe
    Replies:
    4
    Views:
    7,740
    Chris Theis
    Jan 22, 2004
  4. solartimba

    getline problem

    solartimba, Apr 6, 2004, in forum: C++
    Replies:
    1
    Views:
    424
    Leor Zolman
    Apr 6, 2004
  5. Alex

    getline problem

    Alex, Jun 5, 2004, in forum: C++
    Replies:
    6
    Views:
    502
    Victor Bazarov
    Jun 6, 2004
Loading...

Share This Page