Click here to Skip to main content
15,877,296 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a data like this
 ID         ITEM NO
45824587	  2545654
32589662      5878985
11414252      2145477
25789632      2458926

I want to allocate a char pointer and want to store the result using comma like
char *ptr = 45824587,32589662,11414252,25789632;2545654,5878985,2145477,2458926

Please provide me with the code

It doesn't quite work like that.
We do not do your work for you.
If you want someone to write your code, you have to pay - I suggest you go to and ask there.

But be aware: you get what you pay for. Pay peanuts, get monkeys.
Share this answer
Using C++ would make your life easier.
If you have to use C then you must allocate (either statically or dynamically) a big enough buffer (character array) for holding your comma-separated values. Then you have to build the comma-separated values using the fetched result (without knowing how are you actually going to fetch the database results, we cannot help more).
Share this answer
Tarun22 17-Aug-15 12:46pm    
sir i am running query in c like this mysql_query(con, "Select * from table where client_type = 1")
I just want to store the result in char array as shown above
CPallini 17-Aug-15 12:52pm    
You know, you have to perform additional steps in order to actually retrieve the results, see, for instance, this tutorial:
Check out the "Retrieving data from the database" section.
Tarun22 17-Aug-15 12:57pm    
i have to run this query (field = mysql_fetch_field(result)) but i want to get the result comma separated in char array
CPallini 17-Aug-15 13:08pm    
According to the documentation, mysql_fetch_field "Returns the definition of one column of a result set" not the actual data.
You must first be able to actually collect the data and then arrange them using given format.
Tarun22 17-Aug-15 13:32pm    
Thats true suppose first time it has value 123456 then 656563 how do i insert ";" in between.Can i have pseudo code for that?
In C, you may use 'sprintf' inside a loop. You first need to allocate a character array(say ptr) of enough size and initialize it with the value of the first record. Then inside a loop do the following,

sprintf(ptr, "%s, %s", ptr, nextValue);
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900