How to use lib function "getline"

I

Ian Collins

goose said:
Default said:
Chen shuSheng wrote:


I have a code:
---------------------------
#include <iostream.h>
#include <stdlib.h>

int main()
{ int max=15;
char line[max];
getline(line,max);
system("PAUSE");


getline() is not standard C therefore out of topic here.
You should ask at comp.unix.programmer or
comp.os.linux.development.apps




However, it is a standard C++ function.


No it isn't, its an extension in the gnu C library.
<OT>Nonsense, it's a couple of standard functions.</OT>
 
G

goose

Default said:
Chen shuSheng wrote:

I have a code:
---------------------------
#include <iostream.h>
#include <stdlib.h>

int main()
{ int max=15;
char line[max];
getline(line,max);
system("PAUSE");

getline() is not standard C therefore out of topic here.
You should ask at comp.unix.programmer or
comp.os.linux.development.apps



However, it is a standard C++ function.

No it isn't, its an extension in the gnu C library.
Please don't give redirects
unless you are ACTUALLY familiar with the problem.

We all do your best :)
The correct group is comp.lang.c++.
I believe comp.unix.programmer and comp.os.linux.development.apps
are correct.

goose,
 
A

Andrew Poelstra

Keith Thompson said:
Not unless you write it yourself.


The book you mentioned, K&R, was written by Brian Kernighan and Dennis
Ritchie. Ken Thompson is another author who has worked with both of
them. I'm not related to him.


The code you posted uses a non-standard "getline" function without
defining it. I don't believe that mistake exists in K&R.

On page 70 of the original K&R, getline() is used in code. Flipping
back to page 68, the line "cc main.c getline.o index.o" is shown,
indicating that getline has indeed been defined... one page 26.

Perhaps the OP should learn how to read his index, or perhaps he
should purchase a newer version of K&R.
 
J

Jack Klein

Default said:
Chen shuSheng wrote:

I have a code:
---------------------------
#include <iostream.h>
#include <stdlib.h>

int main()
{ int max=15;
char line[max];
getline(line,max);
system("PAUSE");
getline() is not standard C therefore out of topic here.
You should ask at comp.unix.programmer or
comp.os.linux.development.apps


However, it is a standard C++ function. Please don't give redirects
unless you are ACTUALLY familiar with the problem.

It appears to me that both you and I are guessing at
what the original poster's problem is. It could be that
your guess is correct and mine isn't but unless Chen
elaborates you can't be sure what the correct redirection
is.

And needless to say that I don't offer suggestions unless
I believe (perhaps mistakenly) that I understand the
problem.

Actually, I think the <iostream.h> moves the other guess into the
range of extremely high probability.
 
K

Keith Thompson

goose said:
Default said:
(e-mail address removed) wrote: [...]
getline() is not standard C therefore out of topic here.
You should ask at comp.unix.programmer or
comp.os.linux.development.apps

However, it is a standard C++ function.

No it isn't, its an extension in the gnu C library.

It's a floor cleaner *and* a dessert topping!

getline is a function (method?) in the C++ strings library, *and* a
GNU extension to the standard C library, *and* a function implemented
as an example in K&R. (I think the latter is the only one that's
relevant here.)

It's also an ordinary unreserved identifier; any C program is free to
define it any way it likes (but, as with any other identifier, you
have to be careful of naming conflicts).
 
D

Default User

It appears to me that both you and I are guessing at
what the original poster's problem is. It could be that
your guess is correct and mine isn't but unless Chen
elaborates you can't be sure what the correct redirection
is.

Yes. His later posts do indicate that he is trying some out of date
C++, but I have been edumacated that getline() is also a gcc extension.
And needless to say that I don't offer suggestions unless
I believe (perhaps mistakenly) that I understand the
problem.

Sure. I was overly grumpy.



Brian
 
D

Default User

goose said:
No it isn't, its an extension in the gnu C library.

It is both, although the C++ version has a different signature.
I believe comp.unix.programmer and comp.os.linux.development.apps
are correct.

Subsequent messages from the OP seem to indicate that he was trying to
use outdated C++ (iostream.h) functionality.



Brian
 
K

Keith Thompson

Default User said:
It is both, although the C++ version has a different signature.


Subsequent messages from the OP seem to indicate that he was trying to
use outdated C++ (iostream.h) functionality.

Yes, but I think the getline() function he was trying to use was
actually one presented as an example in K&R.
 
D

Default User

Default said:
(e-mail address removed) wrote:

Yes. His later posts do indicate that he is trying some out of date
C++, but I have been edumacated that getline() is also a gcc
extension.

And it then turns out he was really talking about neither, exactly.



Brian (exceedling sorry he ever got involved)
 
M

Mark McIntyre

I have a reference book "C/C++ lib" which tells me that this pototype is in
"iostream.h".

Hopefully it also mentions that "iostream.h is a C++ header, and
therefore not usable in C.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
G

goose

Default said:
Default User wrote:

Similarly, I've been informed that getline is some
damn C++ "thingy" :-(
And it then turns out he was really talking about neither, exactly.



Brian (exceedling sorry he ever got involved)

At this point, you're not the only sorry one.

goose,
ambiguity is the route of all evil :)
 
C

CBFalconer

jacob said:
.... snip ...

Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.

No you don't. I virtually never use any sort of IDE under
windows. I do use both info and man under windows. However none
of these would ever show getline as a standard, because it just
isn't. It is whatever you define it to be.
 
D

Default User

Keith said:
Yes, but I think the getline() function he was trying to use was
actually one presented as an example in K&R.

Indeed. As I said in another reply, I sincerely wish I'd never got
involved. Especially as I redirected to clc++ and had to post an answer
over there.



Brian (sadder but wiser)
 
D

Dave Thompson

Keith said:
{ int max=15;
char line[max];


This is a variable-length array. This is standard in C99, but not all
compilers support it.

<OT>It's also standard in C++, but if you're trying to write a C++
program you should ask in comp.lang.c++.</OT>
No, it's an error in C++, where VLAs are absent.

<OT> VLAs are absent, but constant expressions are defined
differently. The example given is indeed illegal in C++, but
{ const int max = 15; char line[max]; ... }
is legal in C++(98).

- David.Thompson1 at worldnet.att.net
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top