Practice

Scroll



What is the exact out of the following program?  Show your intermediate work.

 // Scroll
 //
 #include <stdio.h>
 #include <string.h>
 #define MAX_CHAR 6

 void scroll(char s[])
 {
         int i;
         char t;
         printf("|%s|\n", s);
         if (strlen(s) > 1) {
                 t = s[0];
                 for (i = 1; s[i] != '\0'; i++)
                         s[i-1] = s[i];
                 s[i-1] = t;
         }
 }

 void insert(char n[], char s[])
 {
         int i, j, k = 0, len = strlen(s);
         putchar('|');
         for (i = 0; i < len; i++)
                 putchar('-');
         printf("|\n");
         i = len - strlen(n);
         if (i < 0)
                 i = 0;
         for (j = len - 1; j >= i; j--) {
                 s[len-1] = n[k];
                 scroll(s);
                 k++;
         }
         for (j = i - 1; j >= 0; j--) {
                 s[len-1] = '.';
                 scroll(s);
         }
 }

 int main(void)
 {
         int i;
         char message[MAX_CHAR+1] = "Hello.";
         for (i = 0; i < strlen(message); i++)
                 scroll(message);
         scroll(message);
         insert("Bye", message);
         return 0;
 }
  Top  Go Back to the Top of this Page



  Designed by Chris Szalwinski   Copying From This Site