[vdr] plugin writing - need help with C

Jose Alberto Reguero jareguero at telefonica.net
Fri Apr 13 13:25:21 CEST 2007


El Viernes, 13 de Abril de 2007, Simon Baxter escribió:
> > One more thing - how do I convert a %d variable to a %s string first?
> >
> > My 'txt' variable is currently an integer.
>
> Strike that - works a treat:
>
> <snip>
> void cRedRemote::Tune(int channel)
> {
>     char      buf[10];
>     sprintf(buf,"%d",channel);
>     log(1,"Setting digibox to channel %d",channel);
>      char *p = buf;
>
> /* SBB Fudge
> */
>  char txt2[strlen(buf) * 2];
>         int i = 0;
>         int j = 0;
>         while (i < strlen(buf) - 1) {
>                 txt2[j] = buf[i];
>                 i++;
>                 j++;
>                 txt2[j] = ' ';
>                 j++;
>         }
>         txt2[j] = buf[i];
>         j++;
>         txt2[j] = '\0';
>
> log(0,"SBB Channel Produced by Fudge '%s'",txt2);
>
>         Send(txt2);
> <snip>
>
>
 
If you like more compact code:


 char txt2[strlen(buf) * 2];
        int i = 0;
        int j = 0;
        while (i < strlen(buf) - 1) {
                txt2[j++] = buf[i++];
                txt2[j++] = ' ';
        }
        txt2[j++] = buf[i];
        txt2[j] = '\0';

Jose Alberto




More information about the vdr mailing list