Hi, sorry to bother you guys.
I’m still new to coding and you’ll notice if you take a look on the code
I’m posting below.
I use this piece of code to colorize a name 3 – 12 letters. 

For example if my name is Desindit and I would like to colorize it.
I would do something like colorize_string(name, “R”, “r”, “w”);
And the string would become “&RDe&rs&win&rd&Rit”
If you notice this code isn’t finished yet, since it only colorize
strings with 8 letters. Though looking at my code
It’s pretty much a mess in my eyes, I figured I should use some loops to
colorize the strings, but since the colorizing will be different
depending on how long the name is, I figured it would still be a mess
using loops.
I would be greatful to any help and comments to the mess. Ohh and I
better get some sleep now and when I wake up I’ll realize how stupid I
was that I didn’t get some sleep before writing code. ;)

char *colorize_string (const char *str, const char *c1, const char *c2,
const char *c3 )
{
        char newbuf[MSL];
        static char tempbuf[MSL];

        tempbuf[0] = '\0';

        if (strlen(str) == 7)
        {
                sprintf(newbuf, "&%c%c", *c1, str[0]);
                strcat(tempbuf, newbuf);
                sprintf(newbuf, "%c", str[1]);          
                strcat(tempbuf, newbuf);
                sprintf(newbuf, "&%c%c", *c2, str[2]);
                strcat(tempbuf, newbuf);                
                sprintf(newbuf, "&%c%c", *c3, str[3]);

                strcat(tempbuf, newbuf);                
                sprintf(newbuf, "&%c%c", *c2, str[4]);
                strcat(tempbuf, newbuf);                
                sprintf(newbuf, "&%c%c", *c1, str[5]);

                strcat(tempbuf, newbuf);
                sprintf(newbuf, "%c", str[6]);
                strcat(tempbuf, newbuf);                
        }          
   
        if (strlen(str) == 8)
        {
                sprintf(newbuf, "&%c%c", *c1, str[0]);
                strcat(tempbuf, newbuf);
                sprintf(newbuf, "%c", str[1]);          
                strcat(tempbuf, newbuf);
                sprintf(newbuf, "&%c%c", *c2, str[2]);
                strcat(tempbuf, newbuf);                
                sprintf(newbuf, "&%c%c", *c3, str[3]);

                strcat(tempbuf, newbuf);                
                sprintf(newbuf, "%c", str[4]);
                strcat(tempbuf, newbuf);
                sprintf(newbuf, "&%c%c", *c2, str[5]);
                strcat(tempbuf, newbuf);                
                sprintf(newbuf, "&%c%c", *c1, str[6]);

                strcat(tempbuf, newbuf);
                sprintf(newbuf, "%c", str[7]);
                strcat(tempbuf, newbuf);                
        }          

        return tempbuf;
}


Reply via email to