C++ style 'zelda' text

This is a discussion on C++ style 'zelda' text within the C++ Programming forums, part of the General Programming Boards category; I know how to make the text scroll from left to right in C, as I learnt most of C ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479

    C++ style 'zelda' text

    I know how to make the text scroll from left to right in C, as I learnt most of C before learning C++. But I can't figure out how to make this work in C++. I do not want to mix C code with C++ code as that is bad practice. Does anyone know what changes I need to make to the following code sample from one of my C programs to make it into C++ code?

    This is the code I need, but I wrote it in C ages ago:

    Code:
    int x, size;
    
    char sentc[]="This will scroll from left to right using sleep as speed";
    
     size=strlen(sentc);
     for(x=0;x<size;x++)
     {   
     sleep(40); 
     printf("%c",sentc[x]);
     }
    from what I can gather, I have to change sleep to Sleep and printf to cout. Am I on the right track? Thanks in advance!

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Some very minor changes to what you have should do the trick.
    Code:
    #include <iostream>
    #include <ctime>
    #include <string>
    
    int main() {
       int x, size;
       std::string sentc = "This will scroll from left to right using clock as speed.";
       double start, end;
       size = sentc.size();
     
       for(x=0;x<size;x++) { 
          start = double(clock())/1000;
          end = double(clock())/1000;
          while (end - start < .2)
             end = double(clock())/1000;
          std::cout << sentc[x];
       }
        
        return 0;
    }
    I used <ctime> to do the pausing, because it's simply more standard than sleep().

    EDIT: Oh, of course, to edit the speed the text scrolls, then just change that arbitrary floating point number in the while loop.
    Last edited by SlyMaelstrom; 04-28-2006 at 12:36 AM.
    Sent from my iPadŽ

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    Thanks SlyMaelstrom, that's perfect! I only used sleep as I was taught that from a C book. Very much apprecieated!

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Sleep() is in <windows.h>. NOT standard. Period.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 12:23 AM
  2. Text adventure engine idea. thoughts?
    By suzakugaiden in forum Game Programming
    Replies: 16
    Last Post: 01-15-2006, 04:13 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Replies: 1
    Last Post: 07-13-2002, 05:45 PM

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