The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > Linux
.
google unix.com



Linux RedHat, Ubuntu, SUSE, Fedora, Debian, Mandriva, Slackware, Gentoo linux, PCLinuxOS. All Linux questions here!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux programming venkatgopu Linux 2 09-14-2009 07:14 AM
c programming in linux convenientstore High Level Programming 6 04-07-2008 03:30 PM
Need Help Of Linux Programming luckyvishwa Linux 1 01-01-2007 06:47 AM
Programming C in Linux wizkid High Level Programming 2 05-21-2001 08:55 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-23-2009
venkatgopu venkatgopu is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 6
Post C programming in linux

Hi friends

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".

Thanks & Regards
Venkat Gopu

Last edited by venkatgopu; 09-24-2009 at 12:55 AM..
  #2 (permalink)  
Old 09-23-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
Your program so far needs stdio.h, which you'd include at the top of your file like
Code:
#include <stdio.h>
As for whether your program does what you think it does, I have no idea what you think it does. Right now it just fills the terminal with "Display this statement in 5 row 5 column in disk every time". What do you mean by 'row 5 column 5 in disk'? What do you mean 'every time'?
  #3 (permalink)  
Old 09-25-2009
Corona688 Corona688 is offline
Registered User
  
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 1,929
Quote:
Originally Posted by venkatgopu View Post
Hi friends

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".

Thanks & Regards
Venkat Gopu
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.)
Reply

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0