Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compile error with strtof

Status
Not open for further replies.

qkslvrwolf

Programmer
Jul 9, 2002
28
US
For some reason, this

#include <stdlib.h>

int string2float(char *word)
{
float ret;
ret = 0;
ret = strtof(word, NULL);
return ret;
}

gives me an &quot;unidentified reference to strtof&quot; at the line of ret = strtof(word, NULL);

Which really confuses me, because elsewhere in this program I have almost the samet thing, but with an int ret; and strtol(word, NULL);, which works. Great.

Whats going on here?
 
Just a note, I've corrected the function instantiation to &quot;float string2float(char * word)&quot;
but this obviously hasn't helped with the compile error.
 
Umm, I copied and pasted your function (with the float-correction) and it compiles and runs without so much as a peep and produces correct results.
 
man strtod
man atof vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
phoenix:~/sean % gcc -g functions.c
/var/tmp/ccuTj3uV.o: In function `string2float':
/home1/sabbott/sean/functions.c:104: undefined reference
to `strtof'

hmmm...any idea why my compiler won't handle it?
 
'cause there's no 'strtof' in <stdlib.h>

Only strtod and atof are defined.
Do 'man' as previously suggested. vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Try using the functions:

strtod()
atof()

They produce double results but you can cast to floats if you need that. Just something to think about ;-)

 
From man-page for strtof on my GNU/Linux (Debian) system:

SYNOPSIS
#include <stdlib.h>

double strtod(const char *nptr, char **endptr);
float strtof(const char *nptr, char **endptr);
long double strtold(const char *nptr, char **endptr);

 
I tried man strtod, strtof, and niether worked. the only strto function I could get a man page for was strtol, which obviously returns long integers, so no help. I'll try using strtod and casting to float. (need an exact length). Thanks alot!
I'd still like to know why it compiles for abbeman though
 
Doing the cast from strtod to float worked, thanks alot everyone!
 
what OS are on? vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Some linux flaovr, I'm not entirely sure. Or it might be Unix. I'm SSH ing in to a server. I wasn't filled in on teh details.
 
Well, I have the functions I listed above in the stdlib.h, one of them is strtof.

Guess we might have different versions of libc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top