On Thu, Jul 01, 1999 at 03:19:05PM +1200, Michael Beattie wrote:
> 
> The following problem will help me finish v0.1 of my wizard radio control
> program which I will ITP and upload soon..
> 
> <prepared for flames>
> 
> I know its the wrong place to ask, but its really easy, and I feel stupid
> asking in a newsgroup....
> 
> string with value "number:"
> 
> integer with value "444"
> 
> I want the string to then have the value "number:444"
> 
> this is the actual C code:  (slightly snipped)
> 
>    int freq_num;
>    double freq;
>    char *rad_cmd;
> 
>    freq = atof(optarg);   // optarg is "98.2"
> 
>    freq_num = (int) ((freq - 76) / 0.05);   // gives 444
> 
>    rad_cmd = "number:";
> 
>    What now?  i.e.  rad_cmd+freq_num to give rad_cmd = "number:444"
>    strcat()?
> 
> 
> </prepared for flames>

No, well, yes.. well.. for starters, you need a buffer, not a pointer.
rad_cmd has no space to hold "number:444".  Change it to 
char rad_cmd[x] where x is some number that will hold the maximum size of
the string + 1.

Then you can do...

sprintf( rad_cmd, "number:%u", freq_num );

-- 
Please cc all mailing list replies to me, also.
=========================================================================
* http://benham.net/index.html        <[EMAIL PROTECTED]>           <><  *
* -------------------- * -----------------------------------------------*
* Debian Developer, Debian Project Secretary, Debian Webmaster          *
* <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>  *
* <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>   *
=========================================================================

Attachment: pgprpBUbvKu65.pgp
Description: PGP signature

Reply via email to