Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6744935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:08:36+00:00 2026-05-26T12:08:36+00:00

I have a somewhat stupid problem because it’s supposed to be utterly simple …

  • 0

I have a somewhat stupid problem because it’s supposed to be utterly simple …

Assume I have string:

char *str = "stackoverflow";

I want to print that string one character at a time with some delay after each character:

int i = 0;
while (str[i] != '\0') {
  putchar(str[i]);
  usleep(100000);
  i++;
}

But instead of doing the obvious and right thing, printing a character and waiting 100 ms and doing it over again, it looks like the delay gets accumulated and spit out at once.
So it sleeps happily for about one and a half second and then prints out my string.

Any ideas?
(I did the exact same thing in Ruby without a problem and also tried it using the ‘\r’-method, which also works in Ruby …)

Please help!
Otherwise I can’t do the program for my assignment, which is printing a string; but I don’t want to do it boringly … 😉

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:08:37+00:00Added an answer on May 26, 2026 at 12:08 pm

    Try to flush the buffer in between:

    putchar(str[i]);
    fflush(stdout);
    usleep(100000);
    

    When writing to a terminal, output is usually line-buffered. The actual thing is printed if a \n is encountered or if the buffer fills.

    Alternatively you could disable buffering once and for all at the beginning:

    setbuf(stdout, NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered a somewhat baffling problem with the simple task of filling an
I have somewhat simple problem with my Flash projects. I've installed Flash CS5, created
I have a somewhat simple Client/Server solution running over C# remoting (System.Runtime.Remoting). The MarshalByRef
I have somewhat of a problem. We have a centralized interface engine that will
I have somewhat of a problem. My old webserver (windows 2003) have been replaced,
This may sound somewhat stupid, but I have to know as I'm writing a
I have somewhat interesting development situation. The client and deployment server are inside a
Does VS2008 have somewhat C++0x standard support? DUPLICATE Visual Studio support for new C
I have a somewhat messily-formatted Objective-C code base. Is there a way to have
I have a somewhat complicated branching structure at work (at least for me). It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.