Hi all,
I have what may be a rudimentary question, but I just don’t get it.
I made a little program, it has one argument, an integer.
I take the number (atoi(argv[1]) and use that in a for loop. for each
decrment from the number, I print the line “time remaining: [the
number]” I do this by printing "time remaining: " then for each
decrement printing to backspaces “\b\b” then writing the current number.
I never thought I’d say this, but it works fine in windows, it just
doesn’t work at all in QNX. nothing prints to the screen until the end
of the program
here is the code for windows
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
int main(int argc, char* argv[])
{
if(argc > 1)
{
int time = atoi(argv[1]);
printf(“time remaining: “);
for(int i = time; i > 0; i–)
{
if(i < 10) printf(”\b\b %i”, i);
else printf("\b\b%i", i);
_sleep(1000);
}
printf("\b\b 0\n");
}
return 0;
}
it works fine, just the way I want it to.
but the code in QNX,
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char* argv[])
{
if(argc > 1)
{
int time = atoi(argv[1]);
printf(“time remaining: “);
for(int i = time; i > 0; i–)
{
if(i < 10) printf(”\b\b %i\c”, i);
else printf("\b\b%i\c", i);
sleep(1);
}
printf(“time remaining: 0\n”);
}
return 0;
}
doesn’t print anything until the last line “time remaining: 0”
–
Chris Nasr
cnasr[at]mechtronix[dot]ca
Mechtronix Systems Inc.