Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How can i move a text in C??

neil15neil15 Posts: 1Member
anyone knows how to move a text in C??

if your watching news, it is like the text below ur TV set...

plz help....

thanks...

Comments

  • Ed HallEd Hall Posts: 395Member
    Here's one way to have text crawl across the bottom:

    [code]
    #include
    #include
    #include /* added to provide for gotoxy() function

    /* function defined because gotoxy() is not standard */
    void gotoxy(int x, int y)
    {
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }

    int main(int argc, char *argv[])
    {
    char cText[300];

    strcpy(cText, " ");
    strcat(cText, "This is the message to have crawl across the bottom of your screen. ");
    strcat(cText, " ");

    int d, i, j, tl = strlen(cText)-80;

    for (i=0;i<tl;i++)
    for (j=0;j<80;j++){
    gotoxy(j, 24);
    printf("%c", cText[i+j]);
    for (d=0;d<200000;d++); /* delay */
    }

    system("PAUSE");
    return 0;
    }
    [/code]

    You will have to change the delay value "d<200000" to achieve your desired speed. But, this should get you started...

    Take Care,
    Ed
  • LundinLundin Posts: 3,711Member
    for (d=0;d<200000;d++);


    Never ever write delays like this. The time turns entirely CPU dependant and the program will occupy CPU resources needlessly on top of it.

    A classic bug like the one above was found in the old Pacman game for 80286. When 386 was released, the game turned very fast, and when 486 was released it turned unplayable, since the figures were moving at the speed of light.

    The correct way is to use the Sleep() function in windows.h.
  • Ed HallEd Hall Posts: 395Member
    Thanks Lundin,

    I agree with you about the delay, but when I try the sleep() function it defaults to seconds instead of milliseconds. I didn't pursue why. Is there a way to call the windows.h function over whatever one is being called now?

    Since sleep() didn't work the way I wanted it to, I figured the OP could at least get an idea of how to perform the crawl using the delay loop, but I should have added a caveat.

    Thanks again.

    Take Care,
    Ed
  • wajihwajih lahorePosts: 2Member

    Can yu tell mee exactly how to move the text on the output of screen in c a short wcode sample ?????????ple ?????????****

  • wajihwajih lahorePosts: 2Member

    can yu tell mee exactly how to move the cursor on the output of the screen in c language with a short code sample

Sign In or Register to comment.