A
arnuld
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://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 ?