![]() |
|
#1
|
|||
|
|||
convert double to charhello,
I need to convert a double (20 with 4 digits after decimal) to char [20]. can any oen help. thank you kilgor |
|
#2
|
|||
|
|||
|
this has been discussed in a thread recently. click below:
previous thread Last edited by JdS : 13-May-2004 at 11:30.
Reason: used bbcode for [THREAD] link
|
|
#3
|
||||
|
||||
|
Quote:
And once again, I think that sprintf is the easiest way to do this. I wrote custom functions to do this when I found out that itoa nad ftoa are not standard functions and the *suck* compared to sprintf (my opinion). CPP / C++ / C Code:
Cheers, d |
|
#4
|
|||
|
|||
|
Quote:
double errcnt = 0; char num_errcnt[13]; int fillstruct(); int main() { fillstruct(); return(0); } int fillstruct() { int x; strcpy(num_errcnt, "000006789012"); errcnt = atof(num_errcnt); cout << "numerr " << num_errcnt[11] << endl; cout << "prefix " << errcnt << endl; strcpy(num_errcnt, "000000000000"); cout << "before " << num_errcnt << endl; sprintf(num_errcnt, "%20.4f", errcnt); cout << "after " << num_errcnt << endl; cin >> x; return(0); } error: implicit declaration of function 'int sprintf(...) |
|
#5
|
|||
|
|||
|
you probably dint include the proper header file for sprintf. which is it???? ask dsmith!
|
|
#6
|
||||
|
||||
|
Quote:
I agree mach. (But I usually agree with you anyway )try: CPP / C++ / C Code:
|
|
#7
|
|||
|
|||
|
hm.. thats weird. i just tried it without including stdio.h and it worked. probably because i used namespace std. by the way, why are you CINing x but not doing anything with it? did you mean to return x?
also whats weird is that your compiler assumes that sprintf is of type int! |
|
#8
|
||||
|
||||
|
Quote:
This is a typical error when you don't have a function definition because C/C++ assumes that it returns an int. |
|
#9
|
||||
|
||||
|
Quote:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#10
|
|||
|
|||
|
what do you know! c++ "assumed" something correctly!
__________________
spasms!!! |
Recent GIDBlog
I?m Home by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| using vector or array | oshiotse | C++ Forum | 4 | 16-Apr-2004 11:59 |
| some I/O problems...again | cameron | C++ Forum | 3 | 03-Mar-2004 22:39 |
| (read/write file) newbie need help plz | momotx | C Programming Language | 6 | 28-Jan-2004 14:40 |
| convert long to pointer to char | realpopeye | C++ Forum | 2 | 26-Sep-2003 11:22 |
| char to operator | calculus87 | C++ Forum | 3 | 04-Sep-2003 11:05 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The