Re: getline function

2006-02-20 Thread Michael P. Soulier
On 18/02/06 Tom Grove said:

 That works and I had looked into that earlier...it seems like it does a 
 lot more than just one function from the man page.  I guess I can use 
 that for now but I wonder why getline() is broken in gcc on FreeBSD?

getline() is from glibc. FreeBSD uses it's own libc. 

Mike

-- 
Michael P. Soulier [EMAIL PROTECTED]
Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction.
--Albert Einstein


pgp6gImbNdA1r.pgp
Description: PGP signature


Re: getline function

2006-02-18 Thread Tom Grove

Mike Jeays wrote:

On Fri, 2006-02-17 at 21:54 -0500, Tom Grove wrote:
  
Is there anyone who can compile a program using the getline() function?  
Here is a really simple program to recreate the following error:


##Error##
/var/tmp//ccvYIi4C.o(.text+0x26): In function `main':
: undefined reference to `getline'
##Error##

##Source File##
#include stdio.h

int main() {
char line[10];

getline(line, 10);
printf(%s, line);

return 0;
}
## Source File##

-Tom
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]



I got a bit further by installing the port for getline
(/usr/ports/devel/libgetline), and changed the code slightly to provide
a single parameter. (Look at man getline)

#include stdio.h
#include getline.h

int main() {
char line[10]=test;

getline(line);
printf(%s, line);

return 0;
}

chaucer 29 ~/c $ cc -o getline -I/usr/local/include -L/usr/local/lib
getline.c -lgetline
chaucer 30 ~/c $ getline
testnow
testchaucer 31 ~/c $ 




  
That works and I had looked into that earlier...it seems like it does a 
lot more than just one function from the man page.  I guess I can use 
that for now but I wonder why getline() is broken in gcc on FreeBSD?


-Tom
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Chuck Swiger
Tom Grove wrote:
 Mike Jeays wrote:
[ ... ]
 That works and I had looked into that earlier...it seems like it does a
 lot more than just one function from the man page.  I guess I can use
 that for now but I wonder why getline() is broken in gcc on FreeBSD?

getline() is not part of the standard C library.
What makes you think gcc is broken...?

-- 
-Chuck

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Tom Grove

Chuck Swiger wrote:

Tom Grove wrote:
  

Mike Jeays wrote:


[ ... ]
  

That works and I had looked into that earlier...it seems like it does a
lot more than just one function from the man page.  I guess I can use
that for now but I wonder why getline() is broken in gcc on FreeBSD?



getline() is not part of the standard C library.
What makes you think gcc is broken...?

  
Yeah...I see that after some more research.  So, now I guess my question 
is being that it's not standard and gets() is not safe to use what 
should I use to grab lines?  My gut tells me to copy the getline() 
function from the KR book but I'm not totally sure that's a great idea 
either.  Stupid strings always causing problems!


-Tom
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Tom Grove

Mike Jeays wrote:

On Fri, 2006-02-17 at 21:54 -0500, Tom Grove wrote:
  
Is there anyone who can compile a program using the getline() function?  
Here is a really simple program to recreate the following error:


##Error##
/var/tmp//ccvYIi4C.o(.text+0x26): In function `main':
: undefined reference to `getline'
##Error##

##Source File##
#include stdio.h

int main() {
char line[10];

getline(line, 10);
printf(%s, line);

return 0;
}
## Source File##

-Tom
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]



I got a bit further by installing the port for getline
(/usr/ports/devel/libgetline), and changed the code slightly to provide
a single parameter. (Look at man getline)

#include stdio.h
#include getline.h

int main() {
char line[10]=test;

getline(line);
printf(%s, line);

return 0;
}

chaucer 29 ~/c $ cc -o getline -I/usr/local/include -L/usr/local/lib
getline.c -lgetline
chaucer 30 ~/c $ getline
testnow
testchaucer 31 ~/c $
I also noticed that this code actually doesn't work...I'm not sure why 
either but it doesn't output what gets typed.  Notice that the 'now' 
that gets typed isn't echoed below.


-Tom
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Chuck Swiger
Tom Grove wrote:
 Chuck Swiger wrote:
[ ... ]
 getline() is not part of the standard C library.
 What makes you think gcc is broken...?

 Yeah...I see that after some more research.  So, now I guess my question
 is being that it's not standard and gets() is not safe to use what
 should I use to grab lines?  My gut tells me to copy the getline()
 function from the KR book but I'm not totally sure that's a great idea
 either.  Stupid strings always causing problems!

Depending on what you'd like to do, GNU readline may be a fine solution to your
situation.  Otherwise, getch(stdin) with a bit of code to cook DEL/BS/CR/NL,
or just use the getline port as you've already done.  :-)

-- 
-Chuck
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Tom Grove

Chuck Swiger wrote:

Tom Grove wrote:
  

Chuck Swiger wrote:


[ ... ]
  

getline() is not part of the standard C library.
What makes you think gcc is broken...?
  

Yeah...I see that after some more research.  So, now I guess my question
is being that it's not standard and gets() is not safe to use what
should I use to grab lines?  My gut tells me to copy the getline()
function from the KR book but I'm not totally sure that's a great idea
either.  Stupid strings always causing problems!



Depending on what you'd like to do, GNU readline may be a fine solution to your
situation.  Otherwise, getch(stdin) with a bit of code to cook DEL/BS/CR/NL,
or just use the getline port as you've already done.  :-)

  
Okay...I think I'm either an idiot or going slowly insane.  I'll admit 
I'm not the most savvy C programmer but the following code gives me an 
error:


## Source File##
#include stdio.h
#include readline/readline.h
#include readline/history.h

int main() {
   char *line;

   line = readline(Test: );

   return 0;
}
##Source File##

##Error##
/var/tmp//ccqxIZxQ.o(.text+0x25): In function `main':
: undefined reference to `readline'
##Error##

What sucks is that readline() seems like it would be the perfect 
solution.  I'm not doing anything special but my I don't want to start 
getting into bad habits like using gets().


-Tom
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread James Bailie

Tom Grove wrote:

 ##Error##
 /var/tmp//ccqxIZxQ.o(.text+0x25): In function `main':
 : undefined reference to `readline'
 ##Error##

You forgot to pass -lreadline to the compiler.

--
James Bailie [EMAIL PROTECTED]
http://www.jamesbailie.com
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Mike Jeays
On Sat, 2006-02-18 at 13:00 -0500, Tom Grove wrote:
 Mike Jeays wrote:
  On Fri, 2006-02-17 at 21:54 -0500, Tom Grove wrote:

  Is there anyone who can compile a program using the getline() function?  
  Here is a really simple program to recreate the following error:
 
  ##Error##
  /var/tmp//ccvYIi4C.o(.text+0x26): In function `main':
  : undefined reference to `getline'
  ##Error##
 
  ##Source File##
  #include stdio.h
 
  int main() {
  char line[10];
 
  getline(line, 10);
  printf(%s, line);
 
  return 0;
  }
  ## Source File##
 
  -Tom
  ___
  freebsd-questions@freebsd.org mailing list
  http://lists.freebsd.org/mailman/listinfo/freebsd-questions
  To unsubscribe, send any mail to [EMAIL PROTECTED]
  
 
  I got a bit further by installing the port for getline
  (/usr/ports/devel/libgetline), and changed the code slightly to provide
  a single parameter. (Look at man getline)
 
  #include stdio.h
  #include getline.h
 
  int main() {
  char line[10]=test;
 
  getline(line);
  printf(%s, line);
 
  return 0;
  }
 
  chaucer 29 ~/c $ cc -o getline -I/usr/local/include -L/usr/local/lib
  getline.c -lgetline
  chaucer 30 ~/c $ getline
  testnow
  testchaucer 31 ~/c $
 I also noticed that this code actually doesn't work...I'm not sure why 
 either but it doesn't output what gets typed.  Notice that the 'now' 
 that gets typed isn't echoed below.
 
 -Tom
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]

Yes - that's why I said I got a bit further, not that I had made it
work.  I have never tried to use it before, and would have to experiment
more.

-- 

Mike Jeays
http://ca.geocities.com/[EMAIL PROTECTED]

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Mike Jeays
On Sat, 2006-02-18 at 15:33 -0500, Tom Grove wrote:
 #include stdio.h
 #include readline/readline.h
 #include readline/history.h
 
 int main() {
 char *line;
 
 line = readline(Test: );
 
 return 0;
 } 

It compiles and works with gcc -o readline readline.c -l readline. You
need to tell the loader about the library.
-- 
Mike Jeays
http://ca.geocities.com/[EMAIL PROTECTED]

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Giorgos Keramidas
On 2006-02-18 15:33, Tom Grove [EMAIL PROTECTED] wrote:
Chuck Swiger wrote:
Tom Grove wrote:
Chuck Swiger wrote:
[ ... ]
 getline() is not part of the standard C library.
 What makes you think gcc is broken...?

 Yeah...I see that after some more research.  So, now I guess my question
 is being that it's not standard and gets() is not safe to use what
 should I use to grab lines?  My gut tells me to copy the getline()
 function from the KR book but I'm not totally sure that's a great idea
 either.  Stupid strings always causing problems!


 Depending on what you'd like to do, GNU readline may be a fine
 solution to your situation.  Otherwise, getch(stdin) with a bit of
 code to cook DEL/BS/CR/NL, or just use the getline port as you've
 already done.  :-)

 Okay...I think I'm either an idiot or going slowly insane.  I'll admit
 I'm not the most savvy C programmer but the following code gives me an
 error:

 ## Source File##
 #include stdio.h
 #include readline/readline.h
 #include readline/history.h

 int main() {
char *line;

line = readline(Test: );

return 0;
 }
 ##Source File##

 ##Error##
 /var/tmp//ccqxIZxQ.o(.text+0x25): In function `main':
 : undefined reference to `readline'
 ##Error##

You're missing an ``-lreadline'' option at the end of your build command.

You may be interested to know that the BSDs have editline(3) too, a
command-line editing library that supports at least `some' of the GNU
readline features, but is BSD-licensed:

% man editline

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-18 Thread Giorgos Keramidas
On 2006-02-18 12:54, Tom Grove [EMAIL PROTECTED] wrote:
Chuck Swiger wrote:
Tom Grove wrote:
Mike Jeays wrote:
 That works and I had looked into that earlier...it seems like
 it does a lot more than just one function from the man page.
 I guess I can use that for now but I wonder why getline() is
 broken in gcc on FreeBSD?

 getline() is not part of the standard C library.
 What makes you think gcc is broken...?

 Yeah...I see that after some more research.  So, now I guess my
 question is being that it's not standard and gets() is not safe
 to use what should I use to grab lines?  My gut tells me to
 copy the getline() function from the KR book but I'm not
 totally sure that's a great idea either.  Stupid strings always
 causing problems!

This is a frequently recurring question in comp.lang.c.  There
are perfectly portable ways to use only ANSI C functions to read
a full line of text, allocating dynamically as much memory as
needed.

For example, a search in the archives of the newsgroup will
provide easily pointers to safe ways to use fgets() to read a line.

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


getline function

2006-02-17 Thread Tom Grove
Is there anyone who can compile a program using the getline() function?  
Here is a really simple program to recreate the following error:


##Error##
/var/tmp//ccvYIi4C.o(.text+0x26): In function `main':
: undefined reference to `getline'
##Error##

##Source File##
#include stdio.h

int main() {
   char line[10];

   getline(line, 10);
   printf(%s, line);

   return 0;
}
## Source File##

-Tom
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: getline function

2006-02-17 Thread Mike Jeays
On Fri, 2006-02-17 at 21:54 -0500, Tom Grove wrote:
 Is there anyone who can compile a program using the getline() function?  
 Here is a really simple program to recreate the following error:
 
 ##Error##
 /var/tmp//ccvYIi4C.o(.text+0x26): In function `main':
 : undefined reference to `getline'
 ##Error##
 
 ##Source File##
 #include stdio.h
 
 int main() {
 char line[10];
 
 getline(line, 10);
 printf(%s, line);
 
 return 0;
 }
 ## Source File##
 
 -Tom
 ___
 freebsd-questions@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-questions
 To unsubscribe, send any mail to [EMAIL PROTECTED]

I got a bit further by installing the port for getline
(/usr/ports/devel/libgetline), and changed the code slightly to provide
a single parameter. (Look at man getline)

#include stdio.h
#include getline.h

int main() {
char line[10]=test;

getline(line);
printf(%s, line);

return 0;
}

chaucer 29 ~/c $ cc -o getline -I/usr/local/include -L/usr/local/lib
getline.c -lgetline
chaucer 30 ~/c $ getline
testnow
testchaucer 31 ~/c $ 



-- 
Mike Jeays
http://ca.geocities.com/[EMAIL PROTECTED]

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]