Thread View: att.lang.c++
2 messages
2 total messages
Started by morano
Thu, 22 Nov 2001 10:47
string pointer trouble
Author: morano
Date: Thu, 22 Nov 2001 10:47
Date: Thu, 22 Nov 2001 10:47
11 lines
1507 bytes
1507 bytes
my function computes some unsigned integer from a string pointer. char *string = "text"; then my function returns 54750. as an integer. Now i want to append this integer to the string using strcat from string.h, but how can i translate this integer value to ascii character values ? And is there a way i can let char * point to HEX value and it will internally translate it to ascii char ?? Thanks
Re: string pointer trouble
Author: Yakov
Date: Mon, 03 Dec 2001 07:36
Date: Mon, 03 Dec 2001 07:36
38 lines
2406 bytes
2406 bytes
The easiest way to append is to use sprintf function, which is quite similar to printf, except that it prints into the specified buffer: const char* text = "this is my text"; int num = MyconvertFunction(text); char temp[11]; // Should be enough for 32 bit signed int. ( 9 positions + sign + trailing zero ) sprintf(temp,"%d",num); If you allocate enough memory to contain your original text and the string representation of the number, you can do: char temp[100]; // my string will never be longer sprintf(temp,"%s%d",text,num); I'm not sure I understand your second question. Yakov. "morano" <alomrani@emirates.net.ae> wrote in message news:9tikso$9od2@news-dxb.emirates.net.ae... > my function computes some unsigned integer from a string pointer. > char *string = "text"; then my function returns 54750. as an integer. > > Now i want to append this integer to the string using strcat from string.h, > but how can i translate this integer value to ascii character values ? > > And is there a way i can let char * point to HEX value and it will > internally translate it to ascii char ?? > > > Thanks > > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads