473,503 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can any one show me the proper path do this

8 New Member
Hello friends,

I have arr of int , now i want to save it in a memory allocated in heap and But the memory will be of type char* with comma in betn them.

I mean finally i want the data in below format

char * str = "100,101,102,103"
can any one guide me how to do that in a simplest way.


Thanks
Dec 8 '08 #1
4 1131
kishore84
8 New Member
if the query is not clear.please let me know.



Thanks
Dec 8 '08 #2
vmpstr
63 New Member
assuming that you allocate enough space to the char*, you can use sprintf in a loop

you want to initialize your str to an empty string, and then keep printing to the end of it. You know the end of the string with either strlen or some calculation using sprintf's return code.

In my opinion that would be as simple as any other approach
Dec 8 '08 #3
donbock
2,426 Recognized Expert Top Contributor
How big does this heap allocation need to be? Look at <limits.h> to see the maximum number of digits for the appropriate integer type. typically, the number of characters needed corresponds to the minimum value due to the negative sign. Let's call the characters needed for one integer 'C'. Looks like you want a comma separator between each value. You also need a null terminator at the end of the string.

For N integers, a heap buffer guaranteed to hold a string representation of the integers is N*(C+1).

Even if this size allocation is "guaranteed" to be big enough, it is still good practice to include error checking code to prevent you from writing past the end of the heap buffer. Also, don't forget to verify that the heap allocation succeeded.

This suggestion requires you to examine <limits.h> to count the number of digits in INT_MIN, and hard code that count into your program. Can you think of way to write your program so that it automatically adapts to changes in <limits.h> if you recompile it on other platforms? That's the essence of writing portable software.
Dec 8 '08 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Don't overlook using itoa() and strcat().
Dec 9 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3794
by: Erick Bodine | last post by:
I am trying to set a new environment variable on a W2k machine with only partial success. The name("SSID") and value("ASIM") show up correctly in the registry and when I go to "System...
3
5757
by: Maxwell2006 | last post by:
Hi, I am using Visual Studio 2005. I have added a DLL into GAC. I can confirm that by going to C:\WINDOWS\assembly and see the assembly name.
1
5935
by: Riky | last post by:
hi i have a windows application. I am select the folder or file name from the folderbrowserdialog box and to delete the folder or file i am calling the following code. Public Function...
1
13900
by: mumbaisalsa | last post by:
hi all, i want to run the slide show say ten slides and then close it , but in my code given below it opens the slide show and closes immediately ... .. please give me a solution to this...
8
5640
by: Anuhas | last post by:
Dear Experts, My project involves developing a Windows Application where i need to load a picture and i used the following code, Bitmap myBitmap3 = new Bitmap(@"C:\App\images\logo.bmp"); ...
3
4849
by: =?Utf-8?B?RGV2b24=?= | last post by:
Is it possible to retrieve a proper/invariant file or directory name using a lowercase full path string without having to resort to a call to GetDirectories()/GetFiles() using the...
22
1649
by: PW | last post by:
Hi All, I go into debug mode with the code below and varReturnVal is Null, but the code still is run. Any idea why? Dim varReturnVal As Variant Dim intDogID As Integer
1
2491
by: swetha123 | last post by:
hello, Can any one please tell me I am Using php,Mysql,CSS to build my site In my database i have small images and large images i am show the small images to the right of the main container...
3
2492
by: swetha123 | last post by:
hello, Can any one please tell me I am Using php,Mysql,CSS to build my site In my database i have small images and large images i am show the small images to the right of the main container...
2
2611
by: Coxmg | last post by:
Here is the code, ACCESS 2007: Hello, I have a dialog box that opens on a form that lets the user browse files. I simply want to limit it to Folders, how can I do that? Need ASAP. Thanks. ACCESS...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7451
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.