Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Linux Text Slowdown- HELP PLEASE

Linux Text Slowdown- HELP PLEASE

Scheduled Pinned Locked Moved C / C++ / MFC
linuxquestionhelp
16 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P posidonofthecode

    How can I slow down text with a 2-second timing in between letters? The following will not work: #include main() { /* And yes, sleep(2); actually takes up two whole seconds for some reason */ printf("\n\nH"); sleep(2); printf("e"); sleep(2); printf("y\n\n"); sleep(2); return 0; } /* For some reason this code FIRST executes the "sleep();" functions first. It then gives the output "Hey" all in one shot four seconds later. I am using Ubuntu if that helps, but I guess everyone else is using Windows because it seems to work on their computers. */

    E Offline
    E Offline
    Eytukan
    wrote on last edited by
    #2

    char* pchText = "Ghost types"; while(*pchText!='\0') { cout<<*pchText++; Sleep(2000); } return 0; tell me what this do in you machine. I'm waiting.

    He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

    P T 2 Replies Last reply
    0
    • E Eytukan

      char* pchText = "Ghost types"; while(*pchText!='\0') { cout<<*pchText++; Sleep(2000); } return 0; tell me what this do in you machine. I'm waiting.

      He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

      P Offline
      P Offline
      posidonofthecode
      wrote on last edited by
      #3

      I will not be able to write code until I get home, school computers wont let me install compilers :^)

      1 Reply Last reply
      0
      • E Eytukan

        char* pchText = "Ghost types"; while(*pchText!='\0') { cout<<*pchText++; Sleep(2000); } return 0; tell me what this do in you machine. I'm waiting.

        He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #4

        VuNic wrote:

        *pchText++;

        you know this is bad coding, but you push a newbie into it ?! evil you are ;P

        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        P E J 4 Replies Last reply
        0
        • T toxcct

          VuNic wrote:

          *pchText++;

          you know this is bad coding, but you push a newbie into it ?! evil you are ;P

          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          P Offline
          P Offline
          posidonofthecode
          wrote on last edited by
          #5

          Hey VuNic could you tell me why this is conflicting code and give me an alternative? :rolleyes:

          E 1 Reply Last reply
          0
          • T toxcct

            VuNic wrote:

            *pchText++;

            you know this is bad coding, but you push a newbie into it ?! evil you are ;P

            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #6

            lol it isn't bad if we get used to. well, to newbies yes, may be you are right, let him find that out. :) sooner or later he'll find something like that and it's helps him there ;)

            He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

            C 1 Reply Last reply
            0
            • T toxcct

              VuNic wrote:

              *pchText++;

              you know this is bad coding, but you push a newbie into it ?! evil you are ;P

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              E Offline
              E Offline
              Eytukan
              wrote on last edited by
              #7

              So you just got a fan. :|

              He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

              1 Reply Last reply
              0
              • P posidonofthecode

                How can I slow down text with a 2-second timing in between letters? The following will not work: #include main() { /* And yes, sleep(2); actually takes up two whole seconds for some reason */ printf("\n\nH"); sleep(2); printf("e"); sleep(2); printf("y\n\n"); sleep(2); return 0; } /* For some reason this code FIRST executes the "sleep();" functions first. It then gives the output "Hey" all in one shot four seconds later. I am using Ubuntu if that helps, but I guess everyone else is using Windows because it seems to work on their computers. */

                A Offline
                A Offline
                Adam Maras
                wrote on last edited by
                #8

                Try calling fflush before each sleep call; this way, the text in stdout's buffer gets pushed to the console immediately:

                printf("\n\nH");
                fflush(stdout);
                sleep(2);

                printf("e");
                fflush(stdout);
                sleep(2);

                printf("y\n\n");
                fflush(stdout);
                sleep(2);

                P 1 Reply Last reply
                0
                • P posidonofthecode

                  Hey VuNic could you tell me why this is conflicting code and give me an alternative? :rolleyes:

                  E Offline
                  E Offline
                  Eytukan
                  wrote on last edited by
                  #9

                  std::string str = "A Good Spirit Types";
                  std::string::iterator it;
                  for ( it=str.begin() ; it < str.end(); it++ )
                  {
                  std::cout <<*it;
                  Sleep(2000);
                  }

                  This one's okay?

                  He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

                  T C 2 Replies Last reply
                  0
                  • E Eytukan

                    std::string str = "A Good Spirit Types";
                    std::string::iterator it;
                    for ( it=str.begin() ; it < str.end(); it++ )
                    {
                    std::cout <<*it;
                    Sleep(2000);
                    }

                    This one's okay?

                    He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #10

                    much much better :rolleyes: it would be even better if you wouldn't put that horrible using namespace std; at the beginning of your code ;P

                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    E 1 Reply Last reply
                    0
                    • T toxcct

                      much much better :rolleyes: it would be even better if you wouldn't put that horrible using namespace std; at the beginning of your code ;P

                      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                      E Offline
                      E Offline
                      Eytukan
                      wrote on last edited by
                      #11

                      That's true. I avoid that too :rolleyes: It's a good practice but I don't feel it's something "horrible". ;)

                      He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

                      1 Reply Last reply
                      0
                      • E Eytukan

                        std::string str = "A Good Spirit Types";
                        std::string::iterator it;
                        for ( it=str.begin() ; it < str.end(); it++ )
                        {
                        std::cout <<*it;
                        Sleep(2000);
                        }

                        This one's okay?

                        He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

                        C Offline
                        C Offline
                        CPallini
                        wrote on last edited by
                        #12

                        I prefer the first release. Just a note, **S**leep is not available on Linux. :)

                        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                        [My articles]

                        E 1 Reply Last reply
                        0
                        • C CPallini

                          I prefer the first release. Just a note, **S**leep is not available on Linux. :)

                          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                          [My articles]

                          E Offline
                          E Offline
                          Eytukan
                          wrote on last edited by
                          #13

                          Yeah even I like the first one. But Tox the tiger commands things and I end up changing to what he asks :D Tox Rox! And yes I just noticed in a Linux site, Linux sleeps a bit different with C++ there. lol ;) . gudnite!

                          He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

                          1 Reply Last reply
                          0
                          • E Eytukan

                            lol it isn't bad if we get used to. well, to newbies yes, may be you are right, let him find that out. :) sooner or later he'll find something like that and it's helps him there ;)

                            He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

                            C Offline
                            C Offline
                            CPallini
                            wrote on last edited by
                            #14

                            I agree, that's not bad code at all. Just code. Newbies should masters such C-like constructs in order to master C++. :)

                            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                            [My articles]

                            1 Reply Last reply
                            0
                            • A Adam Maras

                              Try calling fflush before each sleep call; this way, the text in stdout's buffer gets pushed to the console immediately:

                              printf("\n\nH");
                              fflush(stdout);
                              sleep(2);

                              printf("e");
                              fflush(stdout);
                              sleep(2);

                              printf("y\n\n");
                              fflush(stdout);
                              sleep(2);

                              P Offline
                              P Offline
                              posidonofthecode
                              wrote on last edited by
                              #15

                              AWSOMENESS!!!PERFECT. I got it now. Adam Maras I am forever your servant. Thanks All for your help :-D :-D :-D :-D :-D :thumbsup:

                              1 Reply Last reply
                              0
                              • T toxcct

                                VuNic wrote:

                                *pchText++;

                                you know this is bad coding, but you push a newbie into it ?! evil you are ;P

                                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                                J Offline
                                J Offline
                                Joe Woodbury
                                wrote on last edited by
                                #16

                                That's not bad coding at all.

                                Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups