Solved

Sleep-program

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now