🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: att.lang.c++
Article #106

Re: string pointer trouble

#106
From: Yakov
Date: Mon, 03 Dec 2001 07:36
38 lines
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
>
>
>
Technical Details
Message-ID: <3c037a2d$1@news.barak.net.il>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!212.43.194.69!fr.clara.net!heighliner.fr.clara.net!news.newszilla.com!news.barak.net.il!212.29.208.98
References: <9tikso$9od2@news-dxb.emirates.net.ae>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10ddee,17778c19d5318f29
X-Google-Attributes: gid10ddee,public
X-Google-Thread: 1014db,17778c19d5318f29
X-Google-Attributes: gid1014db,public
X-Google-Thread: 10d4ba,17778c19d5318f29
X-Google-Attributes: gid10d4ba,public
X-Google-Thread: 109fba,17778c19d5318f29
X-Google-Attributes: gid109fba,public
X-Google-ArrivalTime: 2001-12-02 23:33:02 PST
From: "Yakov" <none>
Newsgroups: att.lang.c++,comp.lang.c,comp.lang.c++,no.it.programmering.c
References: <9tikso$9od2@news-dxb.emirates.net.ae>
Subject: Re: string pointer trouble
Lines: 40
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
X-Original-NNTP-Posting-Host: 212.29.208.98
Message-ID: <3c037a2d$1@news.barak.net.il>
NNTP-Posting-Host: 212.150.48.162
X-Original-NNTP-Posting-Host: 212.150.48.162
Date: 3 Dec 2001 01:36:31 -0600
X-Trace: news.newszilla.com 1007364991 212.150.48.162 (3 Dec 2001 01:36:31 -0600)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!212.43.194.69!fr.clara.net!heighliner.fr.clara.net!news.newszilla.com!news.barak.net.il!212.29.208.98