Solved

Sleep-program

Posted on 2003-11-16
2
690 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

777 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