答案 0 :(得分:2)
答案 1 :(得分:1)
您必须在每次迭代中将所有字符移至屏幕右侧。您可以为此使用memmove。
1. create a buffer of the required size based on the horizontal space in the screen
2.print required the number of '\n' to go to the bottom of the screen
while(1)
{
3.add appropriate delay
4./*use memmove to shift all the char to right side of screen*/
memmove(buffer+1, buffer, horizondal_size - 2);
5.add the new character to the starting of the buffer. add '\0' to the last position in the buffer (horizondal_size - 1)
6./*print the buffer with carriage return, then flush the output*/
printf("%s\r",buffer);
fflush(stdout);
}
答案 2 :(得分:0)
答案 3 :(得分:0)
答案 4 :(得分:0)
答案 5 :(得分:-4)
这可行。
#include <stdio.h>
#include <conio.h>
#include <string.h>
//library for sleep() function
#include <unistd.h>
void main()
{
int i,j,n,k;
//text to be srolled
char t[30]="akhil is a bad boy";
n=strlen(t);
for(i=0;i<n;i++)
{
printf("\n");
//loop for printing spaces
for(j=20-i;j>0;j--)
{
printf(" ");
}
/*printing text by adding a character every time*/
for(k=0;k<=i;k++)
{
printf("%c",t[k]);
}
// clearing screen after every iteration
sleep(1);
if(i!=n-1)
clrscr();
}
}