Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Marquee - display text scolling right
08-12-2009, 11:50 PM
Post: #1
Marquee - display text scolling right
Someone posted some C++ windows code for displaying marquee text and I thought well isn't that interesting. He incorporated notepad and a own bunch of other windows stuff that will never work in my Linux world, so I wrote my own code for Linux to display a text message that would scroll to the right in a never ending loop. Now this code was written quickly in the wee morning hours but here it is. Now I thought initially that this would be simple, but you know it was really quite difficult....G4143

You should try writing a program like this....scroll a text message to the right in a never ending loop
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>

//marquee

int mystrlen(char *s)
{
    int i = 0;
    while (*s++)
        ++i;
    return i;
}

char msg[] = "this is the message to display forever and ever and ever!";

int main(int argc, char**argv)
{
    int i;
    int len = mystrlen(msg);
    int start = len - 40;
    int istart = start;

    system("clear");

    while (true)
    {
        --istart;
        for (i = 0; i < 40; ++i)
        {
            if ((istart + i) >= len)
            {
                fputc(msg[(istart + i) - len], stdout);
            }
            else
            {
                fputc(msg[istart + i], stdout);
            }
        }
        if (istart == 0) istart = len;
        fflush(NULL);
        sleep(1);
        system("clear");
    }
    exit(EXIT_SUCCESS);
}
Find all posts by this user
Quote this message in a reply
08-12-2009, 11:59 PM
Post: #2
RE: Marquee - display text scolling right
This is kind of interesting, but i am having problems with sleep() function !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
08-13-2009, 02:30 AM
Post: #3
RE: Marquee - display text scolling right
(08-12-2009 11:59 PM)drdebcol Wrote:  This is kind of interesting, but i am having problems with sleep() function !

If your running this on a Linux box try usleep()...G4143
Find all posts by this user
Quote this message in a reply
08-13-2009, 02:44 AM
Post: #4
RE: Marquee - display text scolling right
I have Windows, but i got used to translating, and i solved the problem . . . i didn't have library included !

There's a fine line between genius and insanity. I have erased this line.
Oscar Levant
There's a fine line between an administrator and black hat hacker. I have erased this line.
Dr DEBCOL
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: