Display a message in one second

This is a discussion on Display a message in one second within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> int main() { // display message printf("Record deleted.\n"); return 0; } How can I display the message ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    127

    Display a message in one second

    Code:
    #include <stdio.h>
    
    
    int main()
    {
    	// display message 
    	printf("Record deleted.\n");
    
    
    	return 0;
    }
    How can I display the message in one second before the program ends?

  2. #2
    Registered User
    Join Date
    Oct 2011
    Posts
    847
    Quote Originally Posted by ulti-killer View Post
    How can I display the message in one second before the program ends?
    How about just sleeping for a second before the program exits (returns from main())?

    A portable programmer might use something along the lines of
    Code:
    #ifdef _WIN32
    #include <windows.h>
    void msleep(unsigned int ms) {
        Sleep(ms);
    }
    #else
    #ifndef BSD_SOURCE
    #define BSD_SOURCE 1
    #endif
    #include <unistd.h>
    void msleep(unsigned int ms) {
        if (ms >= 1000U) sleep(ms / 1000U);
        if (ms % 1000U) usleep(1000U * (ms % 1000U));
    }
    #endif
    to define a more or less portable function msleep(), which takes the number of milliseconds (thousandths of a second) to sleep as a parameter.

    Try that, adding msleep(1000); before your return 0; line.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 05-02-2012, 04:17 PM
  2. Trying to scroll a message across an LED display
    By souldoutt in forum C Programming
    Replies: 5
    Last Post: 11-27-2008, 09:39 PM
  3. Display message after key press?
    By mike77 in forum C Programming
    Replies: 0
    Last Post: 04-06-2007, 12:30 PM
  4. Replies: 1
    Last Post: 05-19-2006, 08:30 PM
  5. Replies: 4
    Last Post: 01-06-2002, 05:22 PM

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