Thread: How to write timed text?

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    673

    How to write timed text?

    I am trying to get my program to write text a letter at a time instead of a entire line at a time how is it that I go about doing that?
    I know this is prolly really obvious but I cant find it in the furoms so I figured I would ask.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    A for loop to print each character - say cout << string[i];
    A delay to wait a while between printing characters - say Sleep(1000);
    Flush output to make sure you see something - say cout.flush();

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    here, i copied the "void sleep" method from some site, and i wrote the code

    Code:
    #include <iostream>
    #include <time.h>
    using namespace std;
    void sleep(unsigned int mseconds)
    {
        clock_t goal = mseconds + clock();
        while (goal > clock());
    }
    int main(){
    char word[] = "Supercalifragilistoiusomg";
    cout << word << endl;
    cout << "now letter byletter people \n" ;
    int x;
    for (x=0;x<26;x++){
    cout << word[x] << " ";
    sleep(100);
    }
    cout << endl;
    cin.get();
    }
    Last edited by rodrigorules; 11-26-2005 at 02:17 PM.

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    is there any way to gt a string length to get it to automaticlly know how many characters are in the string. Because if you make x larger than the string then alot of random characters pop up. So i was wondering if you could make something like
    Code:
    x =strl word[];
    I know that isnt the actually syntax but that is like what I want.

    And thank you very much for helping me with the text display thing.

  5. #5
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Code:
    #include<iostream>
    #include<fstream>
    using namespace std;
    
    int main()
    {
    
    string example = "alksdfhlksdhflkhsflkhsdlfkhsaelkhflksahef";
    int length = example.length();
    cout << length;
    
    
    cout << "Or end a for-loop" << endl;
    
    
    for( int i = 1; i <= example.length(); i++)
    
    cout << i << " " ;
    
    
    return 0;
    }

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Thanks so much Enahs that helps A WHOLE LOT. As far as I knwo this is going to be my last question it have nothing to do with this but better than making a new thread for something this dumb. What is the difference between
    Code:
    #include "program.h"
    and
    Code:
    #include <program.h>
    Because I am making my own headers for my program and I keep having to add them to the include file of my dev-cpp directory before it will let me use them. I need to be able to use them from the program directory not dev-cpp. (Mainly because I want to be able to share my code with other windows users). so they can learn from it.

  7. #7
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    If you wanna use your own headear file use " " - it should be in your directory
    otherwise use <> - this means the header is either in system32 or in compiler directory

    And also when you are determinating the length of a string, that is char[xxx] do it like this:
    Code:
    char string[];
    int length = strlen(string);
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  8. #8
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Code:
    1 C:\Dev-Cpp\Game\Game.cpp In file included from Game.cpp 
    5 C:\Dev-Cpp\Game\game.h colors: No such file or directory. 
     C:\Dev-Cpp\Game\G__~1.EXE Game.o: No such file or directory. 
     C:\Dev-Cpp\Game\G__~1.EXE no input files
    what do those mean? I made my header files and now my program wont run.

  9. #9
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    i think that you have included "game.h"
    but haven't created such file, or maybe you did but haven't placed it in right directory.
    Give us the source!!!
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  10. #10
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    well I cant send you my source. my comp is really really messed up and is barely lettng me get on the net. but anyways I have a FOLDER named game, then I have all my files in it including the source, headers, and whatever else I may need, but it keeps telling me the files dont exist? it is wierd I know they are there but the program says they dont exist. I even tried adding the directory to my include files under project properties and it didnt work.

  11. #11
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    If you have those header files in a separate folder, are you remembering to include that part of the path in your includes?

    Code:
    #incude "game\game.h"

  12. #12
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    Yep that was the problem thanks sean

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Write text file to char array
    By mjh in forum C Programming
    Replies: 2
    Last Post: 04-02-2007, 08:11 AM
  2. Replies: 3
    Last Post: 05-25-2005, 01:50 PM
  3. Some humour...
    By Stan100 in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-06-2003, 10:25 PM
  4. how do i write text on a edit control created on the fly..,
    By mickey in forum Windows Programming
    Replies: 2
    Last Post: 06-27-2002, 08:31 PM
  5. This should be the Cprogramming.com anthem!
    By Brian in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 01-21-2002, 12:01 AM