Hello I would like to ask what's the delay() in vc++ because when I tried using delay, it displays an error message "delay undeclared identifier". :confused:
Printable View
Hello I would like to ask what's the delay() in vc++ because when I tried using delay, it displays an error message "delay undeclared identifier". :confused:
I belive it's sleep(). To find out how to use it, look it up on MSDN
Yeah I saw sleep in msdn but it's in win32 api! I would like to use it in console app.
As long as your console app is being run by Windows (as opposed to actually being MS-DOS or another OS), you can use the sleep() function just like windows.h is another part of the standard library. No need to set up windows.Quote:
Yeah I saw sleep in msdn but it's in win32 api! I would like to use it in console app.
If it is another OS you're using, search google for an appropriate API.
ok thanks I'll try to play around with it.
Sleep(DWORD dwMilliseconds); can you give me a clue how to use it? I'm totally clueless my friend.
DWORD is a double word. It means 4 bytes. It's a term commonly used in assembly programming, and has just been included as another data type in the windows API.
But it's easier than that. Simply send the number of millisecond (1000 per second) that you want to pause for in the parentheses. If you need to represent this number as a variable instead, I would just look for more information about the DWORD data type at MSDN.
hint: If you're going to be searching MSDN, both MSDN and many other users recommend using google instead of MSDN's search engine. Type what you want to search for, add "msdn" on the end, and you're all set.
Sleep(300)
btw Sleep() is different than sleep()
Indeed - C is case sensitive. Make sure you type it correctly.
And Makoy, please fix that typo in your sig... my biggest problem with newbies is that they rarely write properly. ur l33t yo in the hizzy, playas!
[sourcecode]
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <windows.h>
void main ()
{
char ip[15];
cout<<"Enter IP Address: ";
cin>>ip;
cout<<"\nAttempting To Connect: "<<ip;
cout<<"\nConnecting";
Sleep(1000);
cout<<".";
Sleep(1000);
cout<<".";
Sleep(1000);
cout<<".";
Sleep(1000);
cout<<".";
Sleep(1000);
cout<<".";
Sleep(1000);
cout<<".";
Sleep(1000);
cout<<".";
}
[/sourcecode]
I have this problem that when I execute a file, instead of delaying the "." the delay took effect after I input a file. How can I delay the cout<<"." one by one?
1) main should return an int. Also return 0 at the end of your main function.
2) conio.h is a non-standard header. I don't see why you need it in this program, so don't use it as it will make it difficult for others to help you. It's also bad practice for a number of reasons.
3) You can edit your post; just take the "source" out of your code and it'll format your code in a nice font and preserve the spacing.
@Makoy
take a look at this:
Code:#include <windows.h>
#include <stdio.h>
int main()
{
for(int i=0;i<10;i++)
{
printf(".");
Sleep(300);
}
return 0;
}
And I just noticed you're using obsolete C++. In the latest standard, you need to do the following:
- Remove the .h from any standard header files (this does not include windows.h).
- If you use any of the original C header files, precede them with a 'c'.
- You need to specify the namespace you are using. There are a number of ways to do this. Personally, I like to just addCode:#include <cstdlib>
As apposed to
#include <stdlib.h>
below my #include's.Code:using namespace std;
Depending on your compiler, this may or may not be necessary or even allowed. But you should know about it.
YES!!! I got it working already. Sorry bout my sig I do not mean to offend anybody. I'll remove it ASAP. Guys Thanks for the help! I really appreciate it.
You don't have to remove it, if you could just spell "worse" properly.