Software & Finance





Turbo C - Scroll Text using gotoxy and printf functions





Here is the Turbo C Source Code Scroll Text using gotoxy and printf functions

 

The function Scroll will accept a string as input and it will display the scrolling text on the top on the top of the screen Row position 1.

 


Source Code


 

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <dos.h>

#include <conio.h>

 

 

void scroll(const char *str)

{

    int pos = 1;

    int len = strlen(str);

    char buf[128];

    clrscr();

    while(!kbhit())

    {

      gotoxy(pos,1);

      printf("%s", str);

      delay(100);

      gotoxy(pos,1);

      if(pos > 80 - len)

      {

          sprintf(buf, "%%%ds", len);

          printf(buf, " ");

          pos = 1;

      }

      else

      {

          printf(" ");

      }

      pos++;

    }

}

 

int main(int argc, char *argv[])

{

    char message[64];

 

    if(argc < 2)

    {

      printf("Usage: scroll.exe <text>");

      exit(0);

    }

 

    strcpy(message, (const char*) argv[1]);

 

    scroll(message);

 

    return 0;

}

 

Output


C:\TC\Samples> Scroll.exe "Welcome to softwareandfinance.com"

 

Scrolling text of welcome to softwareandfinance.com