Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old January 12th, 2005, 02:45 PM
maljosh maljosh is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: London
Posts: 23 maljosh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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;

}

Reply With Quote
  #2  
Old January 12th, 2005, 08:17 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,374 lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 21 h 14 m 26 sec
Reputation Power: 1376
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.

Reply With Quote
  #3  
Old January 13th, 2005, 04:40 PM
maljosh maljosh is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: London
Posts: 23 maljosh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
tried both time.h and changed to sleep(1);

It didn't work,

Reply With Quote
  #4  
Old January 23rd, 2005, 04:13 PM
hades5k hades5k is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: QC, Canada
Posts: 1 hades5k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via MSN to hades5k
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 : )

Reply With Quote
  #5  
Old January 28th, 2005, 01:43 AM
Scorpions4ever Scorpions4ever is offline
Mad Rater
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 126 Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 31 m 44 sec
Reputation Power: 7
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.

Reply With Quote
  #6  
Old February 24th, 2005, 07:57 PM
anandkanatt anandkanatt is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Location: In everybody's mind
Posts: 74 anandkanatt User rank is Private First Class (20 - 50 Reputation Level)anandkanatt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 7 h 48 m 45 sec
Reputation Power: 4
Send a message via Yahoo to anandkanatt
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!

Reply With Quote
  #7  
Old January 20th, 2008, 11:26 AM
jb5435 jb5435 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2008
Posts: 1 jb5435 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 4 sec
Reputation Power: 0
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++

Reply With Quote
  #8  
Old January 20th, 2008, 10:18 PM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,374 lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)lewy User rank is General 6th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 1 Day 21 h 14 m 26 sec
Reputation Power: 1376
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#

Reply With Quote
Closed Thread

Viewing: ASP Free ForumsOtherProgramming Help > C/C++ problems with the sleep() function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway