|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
C/C++ problems with the sleep() function
i'm trying to print out a string from the array one character at a time. With a short delay between each character. I wanted to use a sleep function in the for loop. But it doesn't recognise the header. I've used many... and still dont' know how exactly sleep function works.
Please help asap. Thank you. #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> char string1[30]; int x; main() { puts("\nEnter the string"); gets(string1); printf("String length is %d\n",strlen(string1)); printf("\nThe string entered was %s\n",string1); for(x = 0; x < strlen(string1);x++) { printf("%c", string1); sleep[1]; } getch(); return 0; } |
|
#2
|
||||
|
||||
|
You need to include the <time.h> header file for the sleep function to work.
The correct way to use the sleep function is: sleep(Duration); Where Duration is the duration of the sleep call in milliseconds. |
|
#3
|
|||
|
|||
|
tried both time.h and changed to sleep(1);
It didn't work, ![]() |
|
#4
|
|||
|
|||
|
if your OS is Windows, you have to include windows.h and you must spell Sleep(n) with an uppercase S.
Forget all this if you're not using Windows : ) |
|
#5
|
|||
|
|||
|
The function is called sleep() in POSIX compliant systems and Sleep() in Windows (note the capital S). Also, the parameter accepted is different. sleep() takes its argument in seconds, whereas Sleep takes it in milliseconds. So, if you want to sleep for a second in Windows, you need to call it as Sleep(1000).
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. |
|
#6
|
|||
|
|||
|
Hey why don't you try delay(), this too does the same thing....
Syntax : delay(N) , where n = Milliseconds I dont know which header file it uses but this fungtion is the most commonly used one. Check it out! |
|
#7
|
|||
|
|||
|
c++ QUESTION
Hi there!I want to know a way that i can make a phrase(ex:"hello")to appear for a while (ex:2 sec)and then dissappear.I'm always talking about c++
|
|
#8
|
||||
|
||||
|
Please don't resucitate old threads.
Take the time to read our FAQs first before posting and create your own thread. --> Thread Closed
__________________
................... ASCII and ye shall receive .................. Knowledge is the only resource on earth that multiplies when shared Support the Shemzilla Project Powered by C# |
| Viewing: ASP Free Forums > Other > Programming Help > C/C++ problems with the sleep() function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|