Wednesday, August 05, 2009

Rotating Text in C

I was just playing around with the arrays in C when this one got on my mind. Nothing new but I never did create something like this myself. So, for that reason I was really excited. Took about 10 minutes after I got the idea. But I'm still not comfortable with the final "Blank Space" character that it has. Anyway, here's the code. When it asks for the rotation times input, just enter any integer.


#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <dos.h>

void main()
{
clrscr();
char data[1][9999];
int len,i,j,k,l,time,n;

printf("Enter any string\n");
gets(data[0]);
printf("How many times do you want the text to rotate?\n");
scanf("%d",&n);

len=strlen(data[0]);
printf("%d\n",len);

for (time=0;time<n;time++)
{ for (i=0,l=0;i<=len;i++,l++)
{ if (l>len)
l--;
clrscr();
for (j=i;j<len;j++)
{ printf("%c",data[0][j]);
}
printf(" ");
for (k=0;k<l;k++)
{ printf("%c",data[0][k]);
}
printf("\n");
delay(60);
}
}

getch();
}


One more thing, when I was trying to find a way to post the code without making it active, I got a new method that actually is supported by today's HTML standards. To post characters like "<" and ">" around codes or elements without making them active, you can just use their values that are used by HTML to show them.
They are:
For "<" - &-lt; [Without the "-"] For ">" - &-gt; [Without the "-"]
This is the method that I used to post the C Code in here. The page was failing to show the stdio.h and other modules like them between those characters as it was gulping it up as HTML code. So, I used those values instead of the direct characters and put the whole code in PRE tag. Pretty neat now it looks.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...