Solved

Sleep-program

Posted on 2003-11-16
2
708 Views
Last Modified: 2010-04-01
I'm trying to make a program whitch sleeps n seconds, with n the commandline-input:
//////////////////
#include <windows.h>
#include <iostream>

using std::cout;
using std::endl;

int main(int argc,int *argv)
{
  if (argc != 2)
  {
    cout << "Usage : Sleep n\nwith n: number of seconds\n" << endl ;
    exit(-1);
  }
 
  cout << argv[1]*1000 <<endl ;

Sleep(argv[1]*1000);

  return 0;
}

////////////////////
Why doesn't this works ???
Thanks.
0
Comment
Question by:lapijn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 75 total points
ID: 9758638
#include <stdlib.h>

#include <windows.h>
#include <iostream>
using namespace std;


int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        cout << "Usage : Sleep n\nwith n: number of seconds\n" << endl ;
        return -1;
    }

    int n = atoi(argv[1]);
    cout << n*1000 <<endl ;

    Sleep(n*1000);

    return 0;
}
0
 

Author Comment

by:lapijn
ID: 9758654
Thanks, works indeed.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question