![]() |
|
#1
|
|||
|
|||
urgent help:string concathi below there is a simple concatenation program. but i'm getting segmentation fault in it. the problem is that i'm tring to concatenate an integer value to the string but in vain. please help me.
thnx CPP / C++ / C Code:
Last edited by dsmith : 11-Apr-2004 at 08:21.
Reason: Use [c] & [/c] for syntax highlighting.
|
|
#2
|
||||
|
||||
|
Hello Jack. I don't think that strcat is your problem as much as this:
CPP / C++ / C Code:
Also, on strcat, you probably wouldn't get the result you wanted either, because it is going to entirely overwrite the string. I have modified your code to get the results you wanted: CPP / C++ / C Code:
Unfortunately, most compilers don't have itoa (which is the opposite of atoi). If you are so unfortunate, here is a routine that I wrote quite some time ago to convert numbers to a char* CPP / C++ / C Code:
Hope this helps, d |
|
#3
|
||||
|
||||
|
D, the problems I noticed with your routine is that the string[] array is a local buffer that goes out of scope as soon as the routine returns, therefore the data technically does not exist upon return.
Instead you can use sprintf() to convert the number to a string: CPP / C++ / C Code:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#4
|
||||
|
||||
|
Quote:
You are absolutely correct. Like I said, I wrote this a while ago and have always wanted to fix it to be more efficient. I keep forgetting about sprintf. You could avoid strcat all together with sprintf. CPP / C++ / C Code:
Thanks Walt. |
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Urgent ! Pls Help Me ! | mycashmoney | C Programming Language | 4 | 01-Jul-2006 23:49 |
| urgent help:hash function | jack | C Programming Language | 5 | 05-Apr-2004 13:18 |
| urgent: problem + output filters | jack | Apache Web Server Forum | 0 | 04-Feb-2004 23:32 |
| urgent needs :apache + random function | jack | Apache Web Server Forum | 0 | 19-Jan-2004 18:41 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The