Run Error, Commands Executing Simultaneously..
I have a problem with the way my actual program runs. Ive included the code for the delay function that i wrote as well, although i know the function works fine by itself.
My problem is that when the code runs through it appears to do more than one command at the same time, and i need it to stop, finish all the current commands, then perform the next command.
Code:
#include <stdio.h>
#include <sys/time.h>
void Delay(double DTime);
void main()
{
char Word[] = "Goodbye World\n";
int Counter;
printf("Hello");
Delay(5.0);
printf("World... ");
printf("Good\n");
Delay(5.0);
printf("Day\n");
for (Counter = 0; Counter < strlen(Word); Counter++)
{
printf("%c", Word[Counter]);
Delay(0.5);
}
}
void Delay(double DTime)
{
struct timeval TData, ETData;
long Milliseconds, Seconds;
gettimeofday(&TData, NULL);
Milliseconds = ((DTime * 100000) - (int)DTime) + TData.tv_usec;
Seconds = TData.tv_sec + (DTime / 1);
if (Milliseconds > 999999)
{
Milliseconds -= 1000000;
Seconds += 1;
}
for (gettimeofday(&ETData, NULL); ETData.tv_usec < Milliseconds; gettimeofday(&ETData, NULL));
for (gettimeofday(&ETData, NULL); ETData.tv_sec < Seconds; gettimeofday(&ETData, NULL));
}
Now This Outputs The Following:
{5 Second Delay} HelloWorld... Good
{5 Second Later} Day
{0.5 Seconds Later} Goodbye World
Ive been at this all night, so before i go to sleep i figured i should ask the experts. You guys really seem to know your stuff so i thank anyone that took the time to even just read this. Its much appreciated.
Thank again, Raz