Text Typing?

This is a discussion on Text Typing? within the C++ Programming forums, part of the General Programming Boards category; whats the code to make certain parts of a program print out like the computer is typing it out?...

  1. #1
    ray
    ray is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    14

    Text Typing?

    whats the code to make certain parts of a program print out like the computer is typing it out?

  2. #2
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    get the user to input a string into an array. then you just go through a loop outputting each array spot.

    Code:
    ....
    cin>>array[10];
    
    int i=0;
    
    do
    {
        cout<<array[i];
        i++;
    }while(i != 10);
    ....
    is that what you meant?

  3. #3
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    This question was asked less than a week ago - try searching first.
    "Queen and huntress, chaste and fair,
    Now the sun is laid to sleep,
    Seated in thy silver chair,
    State in wonted manner keep."

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Just output char by char, and you can make your program pause between the printint.
    none...

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >whats the code to make certain parts of a program print out like the computer is typing it out?
    Just throw the printing of each character in a loop and pause with each iteration. Once you have that you can add other niceties like changing the time of the pause to create a more realistic human typing effect.
    Code:
    #include <iostream>
    #include <cstdlib>
    // For Sleep, change as required for different systems
    #include <windows.h>
    
    int irand ( int n )
    {
        return (int)( ( (double)rand() / ( RAND_MAX + 1.0 ) ) * n );
    }
    
    int main()
    {
      char msg[] = "This is a message.";
    
      for ( char *it = msg; *it != '\0'; ++it ) {
        std::cout<< *it <<std::flush;
        Sleep ( irand ( 500 ) + 100 );
      }
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My text doesn't display
    By joeprogrammer in forum Game Programming
    Replies: 11
    Last Post: 02-23-2006, 10:01 PM
  2. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 05:13 AM
  3. reading from text file
    By jamez in forum C Programming
    Replies: 3
    Last Post: 11-30-2005, 07:13 PM
  4. Removing text between /* */ in a file
    By 0rion in forum C Programming
    Replies: 2
    Last Post: 04-05-2004, 09:54 AM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21