Thread: delay text in c..

  1. #1
    Registered User nyekknyakk's Avatar
    Join Date
    Aug 2010
    Posts
    35

    delay text in c..

    hi, everyone! i'm currently working on a code that delays a text in c.
    the code is something like this:
    Code:
    char text1[SIZE][SIZE] = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."};
    
    int main() {
    	int i, j;
    	
    	printf("Hi!\n");
    	sleep(1000);
    	printf("Hello!\n");
    	
    	for(i=0; i<=9; i++) 
    		for(j=0; j<=5; j++) {
    			printf("%c", text1[i][j]);
    			sleep(100);
    			}
    	}
    the code above shows this output:
    Code:
    The   quick brown fox   jumps over  the   lazy  dog.
    what can i do to make the input like this:
    Code:
    The quick brown fox jumps over the lazy dog.
    thanks!

  2. #2
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    Instead of:
    Code:
    char text1[SIZE][SIZE] = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."};
    Could you not just have:
    Code:
    char text[] = "The quick brown fox jumps over the lazy dog.";
    Then just have one loop instead of two. Go character by character. That should get rid of the spaces between the words too.

    Edit: Your for loop will look something like this:
    Code:
    for(i=0; i < strlen(text); i++)
    {
           printf("%c", text[i]);
           sleep(100);
    }

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Code:
    for(j=0; j<=5; j++) {
    			printf("%c", text1[i][j]);
    			sleep(100);
    			}
    Says that you're going to print out 6 letters (char's actually), for each word, regardless of the actual length of the word.

    Add some logic (instead of the j<=5), and make the printing stop when j == strlen(text[i]. You'll need to -1 if you want to remove the period from the last word's string.
    Last edited by Adak; 10-16-2010 at 10:53 AM.

  4. #4
    Registered User nyekknyakk's Avatar
    Join Date
    Aug 2010
    Posts
    35
    thanks very much! that was really helpful..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detect OS version
    By linucksrox in forum Windows Programming
    Replies: 4
    Last Post: 05-18-2010, 06:47 AM
  2. Replies: 8
    Last Post: 05-05-2010, 02:43 PM
  3. RichEditCtrl & unicode formatted text
    By ddonate in forum Windows Programming
    Replies: 0
    Last Post: 03-26-2010, 10:50 AM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM