This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is there a function for string rotate ?

"This is a string. "

Rotate to :
"his is a string. T"

Rotate to :
"is is a string. Th"

....

I use it for LCD Display for Scroll.

Parents
  • Off the top of my head:

    char* strrol (char* src)
        {
        char* d = src;
        char* s = d + 1;
        char c = *d;
    
        while (*s++)
            {
            *d++ = *s;
            }
    
        *d++ = c;
        *d = 0;
        } // strrol
    

    That will cost you a lot of time, though, copying the string over and over. You could simply have back-to-back copies of the string. Or, change your transmit routine to use a modular offset and send the string in two pieces:

    void send (char* s, int offset)
        {
        int l = strlen(s);
        int i;
    
        for (i = offset; i < l; ++i)
            {
            OutputToLcd (s[i]);
            }
        for (i = 0; i < offset; ++i)
            {
            OutputToLcd (s[i]);
            }
    
        }
    

    Lots of ways to get this result, with different speed/space tradeoffs.

Reply
  • Off the top of my head:

    char* strrol (char* src)
        {
        char* d = src;
        char* s = d + 1;
        char c = *d;
    
        while (*s++)
            {
            *d++ = *s;
            }
    
        *d++ = c;
        *d = 0;
        } // strrol
    

    That will cost you a lot of time, though, copying the string over and over. You could simply have back-to-back copies of the string. Or, change your transmit routine to use a modular offset and send the string in two pieces:

    void send (char* s, int offset)
        {
        int l = strlen(s);
        int i;
    
        for (i = offset; i < l; ++i)
            {
            OutputToLcd (s[i]);
            }
        for (i = 0; i < offset; ++i)
            {
            OutputToLcd (s[i]);
            }
    
        }
    

    Lots of ways to get this result, with different speed/space tradeoffs.

Children
No data