代码之家  ›  专栏  ›  技术社区  ›  Flash

用C语言实现文本滚动

  •  4
  • Flash  · 技术社区  · 16 年前

    有什么想法吗。。。!

    5 回复  |  直到 11 年前
        1
  •  4
  •   jpinto3912    16 年前

    要打印的字符串存储在81个字符的固定大小数组/向量中(\0终止于位置81),该数组/向量由某些馈送例程更新。这可能来自套接字、键入、文件、调用进程等。。。

    这里的关键图形技巧是用\r而不是\n终止printf。 \r是 回程车厢

        2
  •  1
  •   Nithin P    6 年前

    每次迭代都必须将所有字符移到屏幕右侧。你可以使用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);
    
    }
    
        3
  •  0
  •   vs4vijay    16 年前

    第一个问题很好,但它没有提供那么多的信息。

    您可以执行以下操作:

    简单只要把一个窄条(长度小于屏幕的高度)在屏幕的右侧…然后你必须使用中断启用鼠标指针…还有一件事滚动条的颜色应该不同于背景…现在把鼠标指针的酒吧,只要应用 getPixel(x,y)
    它会给你的颜色,有针对性的像素,并比较它与你的颜色滚动条…如果它匹配,然后你得到滚动条…你可以向上和向下移动。。。

    如果你需要BGI的任何帮助…告诉我…谢谢。。。

        4
  •  0
  •   Clifford    16 年前

    提出一些你应该让面试官知道或询问他们的假设:

    将文本放置在循环缓冲区中,从当前索引打印 其中n是控制台宽度的字符。打印'\r'返回到同一行的开头。在一个时间间隔之后,增加缓冲区索引并重复。

    因此,他们可能一直在寻找的数据结构是 环形缓冲区

    小时 小时

        5
  •  0
  •   Ran    16 年前

    大约3-4年前,当我不得不在我的C年终项目中使用它时,我记得我使用了双面链表来支持向前和向后滚动。 垂直和水平实现。 它是如何实现的:每个“页面”是链表中的一个不同节点,它保存指向上一页和下一页的指针。

    我确信这不是最好的方法,但这是一种方法。

    希望有帮助,

        6
  •  -4
  •   Pang Ajmal PraveeN    9 年前

    这可能有用。

        #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();
    
         }
    
    
        }