473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

getline() problem

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

Jun 27 '08 #1
4 5617
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

Jun 27 '08 #2
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

Jun 27 '08 #3
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.
Jun 27 '08 #4
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
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: John | last post by:
Hello all, I am trying to read in lines into a buffer from a file. Normally I would do this very low-level, but I have come to the conclusion I must stop doing everything the hard way. So, I...
4
by: Joe | last post by:
Hello - I wrote a program that uses ifstream to open an ASCII file and getline() to read in the lines. The problem is when I try to open the same file again later in the code. I used close()...
3
by: Kay | last post by:
I have tried to use following code to read data form a txt file. However , I have found that it would obtain last sentence one more time. How can I solve this problem ? void load(istream& is) {...
11
by: Markus | last post by:
Hi, I want to get an integer from the user. If the user inserts a character instead of an int the program goes crazy. So I tried something like this: This program works pretty well. But if...
9
compman9902
by: compman9902 | last post by:
Thank you for reading this post, first of all. My problem is that whenever I try to use the following code: std::getline(cin,original); Or, the getline method, it compiles fine, but when I run the...
9
by: CyBerFirEZ | last post by:
This is the second time I am experiencing a problem with getline. I've used it before successfully, but I dont know what I'm doing wrong here. Here is the code where the problem is: if (a...
4
by: rpm27 | last post by:
I am having problems with the getline() function. While reading through tutorials to solve it, I copied an example code and compiled it and it gave me the same error: The code is: #include...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.