Prem Soman wrote:

hi!!   i wrote a simple function that returns a string in C
the function fetches values from a table and stores all the value in a string variable 
and then returns it ...This is small  part inside the function i wrote!



while((row = mysql_fetch_row(res)))
       {
       unsigned long *lengths;
       lengths = mysql_fetch_lengths(res);
       for(i=0;i        {
       str = strcat(str,row[i]);
       }
       str = strcat(str,"\n");
       }

but i know that the content in red would rerturn an error!!
how to convert the output of mysql_fetch_row() function to an equivalent string ?


I think, perhaps, the C fragment above has got a bit mangled in transmission. Assuming that
you want to concatenate the individual column and the code is based on manual section
22.4.18 (My 3.23.28 manual) then you need some space in which to construct the
concatenated columns.



unsigned long *lengths; unsigned long tlength,i; MYSQL_ROW row; char *str;

row = mysql_fetch_row(res);
lengths = mysql_fetch_lengths(res); /* gives array of column widths */
tlength = 0;
for(i=0;i<ncols;i++) tlength += lengths[i];
tlength += 1; /* need space for string terminator */


str = (char *)calloc(tlength,sizeof char); /* get some space */

for(i=0;i<ncols;i++) strcat(str,row[i]); /* build the string */

/* don't forget to free the space !! */


---------------------------------
Want to chat instantly with your online friends? Get the FREE Yahoo!Messenger





-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to