• 03-12-2008
-EquinoX-
1. how does the strcat () method actually works in the library?
does it just find where the '\0' location of the string that needs to be concatenated and
take that as the starting index to concatenate with the other string??
2. can someone write me the function atof & sprintf?
• 03-12-2008
mike_g
Quote:

1. how does the strcat () method actually works in the library?
does it just find where the '\0' location of the string that needs to be concatenated and
take that as the starting index to concatenate with the other string??
Yeah pretty much.
Quote:

2. can someone write me the function atof?
No.
• 03-12-2008
-EquinoX-
does the atof actually just use strtol()?
• 03-12-2008
mike_g
Do you mean strtod? And no I imagine it does not. But it would make a nice cheeky solution for an assignment.

I made a function once to convert from float to string as I couldent seem to find one in the standard libraries. But in your case why not just use existing functions?
• 03-12-2008
xuftugulus
Actually if you are on a *nix system, the entire C library source should be available or installable if curiosity is your motive.
• 03-12-2008
-EquinoX-
this is not for an assignment, I am studying for a test to tomorrow
• 03-13-2008
matsp
Writing your own atof() wold be a few dozen lines of code at the very least [unless you want to do it in the obfuscated way].

The principle is, in pseudo-code:
Code:

```recognize sign, save it away. move to next char if there is a sign. while(isdigit(ch)) result = result * 10 + ch-'0'. move to next char if (ch == '.') next char; result += do_decimals(); if (tolower(ch) == 'e') next char; result *= do_exponent(); multiply in sign. do_decimals() {     result = 0;     mul = 0.1;     while(isdigit(ch)) result += (ch-'0') * mul; mul /= 10.0; next ch;     return result; } do_exponent() {     get sign and remember     while(isdigit(ch)) result = result * 10 + (ch-'0'); next char;     return exp(sign * result * ln(10)); }```
--
Mats