C Programming in Linux 

Question:
In my linux application, I want to update output in same place i.e..

I want to display my output in specific location in screen(console output)

ITERATION 1:
(e.g. start diplay from 5th ROW 5th COLOUMN)
if my message is "hi" then 

first time

'h' should print in 5th ROW 5th COL and 'i' should print in 5th ROW and 6th COL.

ITERATION 2:
(e.g. start diplay from 5th ROW 5th COLOUMN)

second time

'h' should print in 5th ROW 5th COL and 'i' should print in 5th ROW and 6th COL.
.
.
ITERATION n:
(e.g. start diplay from 5th ROW 5th COLOUMN)

nth time

'h' should print in 5th ROW 5th COL and 'i' should print in 5th ROW and 6th COL.

Can you please give me simple program?...

I think, this program tell you that what I am expecting?

#include<stdio.h>
int main ()
{
while(1)
{
printf("hi");
}
return 0;
}

output:

r0c0c1c2c3c4c5c6c7c8c9c10.... row->r
hihihihihihihihihihihihihihi.......infinite loop col->c

But, i need to display this "hi" in same place in screen(console output)

output must be:
r5c1c2c3c4c5c6 
................h i (when i press ctrl+c to terminate infinite loop)

In short, I want to overwrite "hi".

Code:

#include<stdio.h>
int main ()
{
  while(1)
  {
          printf("\rhi");
  }
  return 0;
}

The \r character will send the cursor back to the beginning of the line without moving it down. (It doesn't clear the line, either.) If you're being given instructions to go a specific line though, this isn't sufficient, since printf can't go anywhere but across or down. You need to somehow tell the terminal what to do. You do this with ANSI escape sequences, which means printing the ESC character followed by a little bit of data. Here's two simple ones.

Code:

#include <stdio.h>

void cls(void)                  // clear screen
{       printf("\033[2J");                                      }

void gotoxy(int x, int y)       // go to coordinates
{       printf("\033[%d;%dH", y, x);                            }

int main(void)
{
        cls();
        gotoxy(50,5);
        printf("hi\n");
}

This isn't guaranteed to work in all terminals in all circumstances. (I can't think of a modern UNIX terminal it won't work in, but Windows certainly won't like it.)

Have a Linux Problem
Linux Forum - Do you have a Linux Question?

Linux Books
Linux Certification, System Administration, Programming, Networking Books

Linux Home: Linux System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.