473,899 Members | 2,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use lib function "getline"

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

int main()
{ int max=15;
char line[max];
getline(line,ma x);
system("PAUSE") ;
return 0;
}
---------------------
But it can not pass the complier. Message of complier is implicit
declararion of function 'int getline(....)'
Could you help to let it run?
Aug 20 '06
33 25240
Chen shuSheng schrieb:
"jacob navia" <ja***@jacob.re mcomp.fr>
??????:44****** *************** @news.orange.fr ...

I have a reference book "C/C++ lib" which tells me that this pototype is in
"iostream.h ". But now it is not there.
Jacob already answered the rest of your question.
There are two languages, C and C++. Parts of C++ _look_ similar
to C and C++ defines its relationship to C with respect to
linkage. Do not mix the two of them unless you know exactly what
you are doing.

The C++ standard library incorporates the C90 standard library
but by other header names in order to disambiguate between C
and C++ headers.

You obviously got information about a method of a C++ class,
not a function. You probably would have to use it like
cin.getline() or something like that. As it is C++, you
ought to ask for advice in comp.lang.c++ if you want to write
C++.

If you want to write C, then there is no standard C library
function getline() and you can go with fgets() or ggets() as
I mentioned elsethread if you want to stay on the safe side.
Or, if you want to use getline(), you have to obtain it from
somewhere and use it according to its documentation.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Aug 20 '06 #11
Keith Thompson wrote:
"Chen shuSheng" <cs*****@gmail. comwrites:
>>I have a code:
---------------------------
#include <iostream.h>


This is not a standard C header. (C++, maybe?)

>>#include <stdlib.h>

int main()


Better: "int main(void)".

>>{ 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.

--
Ian Collins.
Aug 20 '06 #12

"Keith Thompson" <ks***@mib.org? ?????:ln******* *****@nuthaus.m ib.org...
program you should ask in comp.lang.c++.</OT>
> getline(line,ma x);

There is no "getline" function in standard C.
I see this function in K&R classic "The C programming language". All code
are below.
-----------
#include <ctype.h>
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#define MAXLINE 100
/* rudimentary calculator */
/* atof: convert string s to double */
double atof(char s[]);

int main(void)
{
double sum;
char line[MAXLINE];
int getline(char line[], int max);
sum = 0;
while(getline(l ine,MAXLINE)0)
printf("\t%g\n" , sum += atof(line));
return 0;
}

double atof(char s[])
{
double val, power;
int i, sign;
for (i = 0; isspace(s[i]); i++); /* skip white space */
sign = (s[i] == '-') ? -1 : 1;
if (s[i] == '+' || s[i] == '-')
i++;
for (val = 0.0; isdigit(s[i]); i++)
val = 10.0 * val + (s[i] - '0');
if (s[i] == '.')
i++;
for (power = 1.0; isdigit(s[i]); i++) {
val = 10.0 * val + (s[i] - '0');
power *= 10;
}
return sign * val / power;
}
---------------
That is why I assume "getline" could be find somewhere in C.Also your name
is alike originator of this book. And I confused right now with thinking I
see the author.
After you test this code, you will find a message: "no reference of
getline". Is it the author writing a wrong code?
Aug 20 '06 #13
"Chen shuSheng" <cs*****@gmail. comwrites:
"jacob navia" <ja***@jacob.re mcomp.fr>
??????:44****** *************** @news.orange.fr ...
>Under windows you have to use some kind of IDE and
press F1 with the cursor in the "getline" function call.

I have a reference book "C/C++ lib" which tells me that this pototype is in
"iostream.h ". But now it is not there. My IDE is DEV-C++.And do not have a
reference for "getline". Could you tell me what is your IDE?
I wouldn't trust anything with "C/C++" in the title. C and C++ are
two different languages. Decide which language you want to use. If
your book is that unclear about the difference, get a better book.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #14
Chen shuSheng wrote:
"Keith Thompson" <ks***@mib.org? ?????:ln******* *****@nuthaus.m ib.org...
>>program you should ask in comp.lang.c++.</OT>
>> getline(line,ma x);

There is no "getline" function in standard C.


I see this function in K&R classic "The C programming language". All code
are below.
-----------
#include <ctype.h>
#include <stdio.h>
#include <iostream.h>
This is an obsolete C++ header, why are you using it in what is supposed
to be C?

--
Ian Collins.
Aug 20 '06 #15

"Ian Collins" <ia******@hotma il.com??????:4k ************@in dividual.net...
>#include <ctype.h>
#include <stdio.h>
#include <iostream.h>

This is an obsolete C++ header, why are you using it in what is supposed
to be C?

--
Ian Collins.
Sorry, "#include <iostream.h>" is added by me. Because I debug this program.
Without that, Have a look again.
Aug 20 '06 #16
Ian Collins <ia******@hotma il.comwrites:
Keith Thompson wrote:
[...]
><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.
D'oh! That will teach me not to post off-topic information.

(No, it probably won't.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #17
Chen shuSheng wrote:
"Keith Thompson" <ks***@mib.org? ?????:ln******* *****@nuthaus.m ib.org...
>>program you should ask in comp.lang.c++.</OT>
>> getline(line,ma x);

There is no "getline" function in standard C.


I see this function in K&R classic "The C programming language". All code
are below.
Look back a couple of pages, you will see getline was the previous example!

--
Ian Collins.
Aug 20 '06 #18
"Chen shuSheng" <cs*****@gmail. comwrites:
"Keith Thompson" <ks***@mib.org? ?????:ln******* *****@nuthaus.m ib.org...
>program you should ask in comp.lang.c++.</OT>
>> getline(line,ma x);

There is no "getline" function in standard C.

I see this function in K&R classic "The C programming language". All code
are below.
I don't have my copy of K&R handy at the moment, but ...
-----------
#include <ctype.h>
#include <stdio.h>
#include <iostream.h>
Once again, there is no <iostream.hhead er in standard C, and I don't
believe there's any mention of it in K&R.
#include <stdlib.h>
#define MAXLINE 100
/* rudimentary calculator */
/* atof: convert string s to double */
double atof(char s[]);

int main(void)
{
double sum;
char line[MAXLINE];
int getline(char line[], int max);
This is a declaration of a function called "getline", but there's no
definition for it. If this appeared in an example in K&R, there would
be a definition for the getline function, possibly in a separate file
(though in that case I'd expect the declaration to be in a header).

[snip]
---------------
That is why I assume "getline" could be find somewhere in C.
Not unless you write it yourself.
Also your name is alike originator of this book. And I confused
right now with thinking I see the author.
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.
After you test this code, you will find a message: "no reference of
getline". Is it the author writing a wrong code?
The code you posted uses a non-standard "getline" function without
defining it. I don't believe that mistake exists in K&R.

Incidentally, *please* indent your code; it's very difficult to read
otherwise.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 20 '06 #19
Default User wrote:
sp****@gmail.co m wrote:

>>Chen shuSheng wrote:

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

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

>>getline() is not standard C therefore out of topic here.
You should ask at comp.unix.progr ammer or
comp.os.linux .development.ap ps

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.progr ammer and comp.os.linux.d evelopment.apps
are correct.

goose,

Aug 20 '06 #20

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

Similar topics

4
2795
by: Chen shuSheng | last post by:
I have a code: --------------------------- #include <iostream.h \\ where I assume getline() is inner. #include <stdlib.h> int main() { int max=15; char line; getline(line,max); system("PAUSE");
6
2388
by: bryant058 | last post by:
#include<iostream> #include<cstring> #include<string> #include<iomanip> using namespace std; int main() { string s; char *tokenptr; int space;
3
4949
by: caoliangbj | last post by:
Hi, When I capture the SIGINT event, I encounter a probelm. Please look at the following code, if you don't press any key, the 'getline()' will block there all the time. When I press 'ctrl+c', the function 'getline()' still block there. My question is how can I exit from "getline()" while I just press 'ctrl
0
9845
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11276
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10866
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8043
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7204
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6082
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3320
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.