<br>
Hello all,<br>
I have just joined KLUG, being very keen on learning about Ubuntu and Linux.<br>
<br>
I have run up against a problem whilst working through Ivor Hortons book Beginning C,
3rd edition, using Terminal and CodeBlocks 10.04, on 11.04 'Natty
Narwhal'.<br>
There have been a couple of problems such as getchar and buffering that I have managed
to get solved on line, but now on Page 180 I have hit a brick wall.<br><br>There is a sample program called Simple Simon.<br><br>
Simple Simon is a memory game that posts a sequence of numbers on the
screen for you to memorise. After 1 second the numbers are erased, and
you have to key in what you remember, and hope that you have remembered
correctly.<br><br>
I have not been able to get the program working on terminal or through
code blocks, despite several days of trying to find out what is wrong.<br>
A couple of days ago I decided to start from scratch and write my own
version of the program, building up a bit at a time and perhaps find out
why the original program won't work for me.<br><br>
The problem I have is with the following piece of code which should
give a 1 second delay and then erase the previously printed sequence of
numbers. (This code works OK on XP and Vista):-<br>
<br>
#include <stdio.h><br>
#include <stdlib.h><br>
#include <time.h><br>
<br>
int main()<br>
{<br>
long now = 0;<br>
printf("Hello world!");<br>
now = clock();<br>
<br>
for(;clock() - now<CLOCKS_PER_SEC; ); /*After 1 second delay this "*/<br>
printf("\r"); /*"code should erase the string "Hello world!" */<br>
printf(" ");<br>
<br>
return 0;<br>
}<br><br>
I have tried all sorts of delay methods, but they all end up not doing what I want to do.<br>
Instead of writing Hello world! on the screen and erasing it after 1
second, the screen comes up and after 1 second Hello world! is printed
and erased at the same instant.<br>
I put a break in before the delay, and can see Hello world! is indeed printed.<br><br>
On XP and Vista this program works correctly.<br><br>
I have checked through the man pages, but don't yet know enough to know
if I have found an answer or not. Nothing I have tried works, so would
be mightily obliged if some one will let me know what to do to get this
working.<br>
Many thanks,<br>
Malcolm Jackson.<br clear="all"><br>-- <br>Hello Ubuntu ...... Goodbye Microsoft.<br><a href="mailto:malcom.jackson@ntlworld.com">malcom.jackson@ntlworld.com</a><br>