Sponsored Content
Full Discussion: C programming in linux
Operating Systems Linux C programming in linux Post 302356413 by Corona688 on Friday 25th of September 2009 11:40:39 AM
Old 09-25-2009
Quote:
Originally Posted by venkatgopu
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.)
 

9 More Discussions You Might Find Interesting

1. Programming

Programming C in Linux

Hello, I am a basic programer from back in the 80's/90's. I moved on to visual basic and now I want to learn C. I want to eventually program in Linux. Now, before I get on this band wagon I want to ask a few questions to make sure I am getting started out right. 1. Is C a good language to... (2 Replies)
Discussion started by: wizkid
2 Replies

2. New to Unix. Which books should I read?

Any Usefull Ebooks on Linux Programming?

Hi Forum! Is there anybody who can tell me where I can find some cool books on linux ( RH exclusively! if possible ) programming? :p (2 Replies)
Discussion started by: confusedoflife
2 Replies

3. Linux

Need Help Of Linux Programming

hi frnds i need help on linux programming as well as how to configure linux. if u feel free than plz forward me the mail so that i can go through. email removed thanx regards :) vishwa pratap singh (1 Reply)
Discussion started by: luckyvishwa
1 Replies

4. UNIX for Dummies Questions & Answers

Linux Programming in JAvA

is it advisible to do Linux Programming in JAVA.. If so, whats the advantage over C++ or C.. Cud anyone also help me out by providing some links in this regard.. Would be highly appreciated.. (1 Reply)
Discussion started by: srikumar_cs
1 Replies

5. Programming

c programming in linux

can you guys please let me know what are some of the c programming environment program? you know the ones with checking syntax and auto indentation and such.. dont want to just use vi (although someone did mention to me that in vim, there are capabilities.. but not sure how) thanks in advance. (6 Replies)
Discussion started by: convenientstore
6 Replies

6. Linux

Linux programming

Hi friends! I am new be in Linux system programing. Can you help me to get running processes statistics (pid, uid, %cpu, %mem, pri, ni) without using any commands like TOP, PS. Can you tell me any system call available to get %cpu only or %mem only? Even i include... (2 Replies)
Discussion started by: venkatgopu
2 Replies

7. Shell Programming and Scripting

Shell programming in Linux

Hi, I have been working on Sun Solaris since a long time. Recently I got to work on RH Linux. My Linux version details are: Linux 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux I have a simple command in my shell script: export BKPTAG=`date... (3 Replies)
Discussion started by: sagarparadkar
3 Replies

8. UNIX for Dummies Questions & Answers

From iOS programming to Linux system programming

Hello. I like Linux and C programming language. Allways wanted to understand kernel and become a Linux system programmer. And I also like Objective-C and iOS. These two programming areas have relations: 1. Linux and iOS are UNIX-like systems, POSIX compliant. 2. It is useful to know C language... (2 Replies)
Discussion started by: Rockatansky
2 Replies

9. Red Hat

Linux programming

Develop a program to display file given on the command line to STDOUT, please give sample program (2 Replies)
Discussion started by: ainstin
2 Replies
COL(1)								   User Commands							    COL(1)

NAME
col - filter reverse line feeds from input SYNOPSIS
col [options] DESCRIPTION
col filters out reverse (and half-reverse) line feeds so the output is in the correct order with only forward and half-forward line feeds, and replaces white-space characters with tabs where possible. This can be useful in processing the output of nroff(1) and tbl(1). col reads from standard input and writes to standard output. OPTIONS
-b, --no-backspaces Do not output any backspaces, printing only the last character written to each column position. -f, --fine Forward half line feeds are permitted fine mode. Normally characters printed on a half-line boundary are printed on the following line. -p, --pass Force unknown control sequences to be passed through unchanged. Normally, col will filter out any control sequences from the input other than those recognized and interpreted by itself, which are listed below. -h, --tabs Output tabs instead of multiple spaces. -x, --spaces Output multiple spaces instead of tabs. -l, --lines number Buffer at least number lines in memory. By default, 128 lines are buffered. -V, --version Output version information and exit. -H, --help Output help and exit. NOTES
The control sequences for carriage motion that col understands and their decimal values are listed in the following table: ESC-7 reverse line feed (escape then 7) ESC-8 half reverse line feed (escape then 8) ESC-9 half forward line feed (escape then 9) backspace moves back one column (8); ignored in the first column newline forward line feed (10); also does carriage return carriage return (13) shift in shift to normal character set (15) shift out shift to alternate character set (14) space moves forward one column (32) tab moves forward to next tab stop (9) vertical tab reverse line feed (11) All unrecognized control characters and escape sequences are discarded. col keeps track of the character set as characters are read and makes sure the character set is correct when they are output. If the input attempts to back up to the last flushed line, col will display a warning message. SEE ALSO
expand(1), nroff(1), tbl(1) STANDARDS
The col utility conforms to the Single UNIX Specification, Version 2. The -l option is an extension to the standard. HISTORY
A col command appeared in Version 6 AT&T UNIX. AVAILABILITY
The col command is part of the util-linux package and is available from Linux Kernel Archive <ftp://ftp.kernel.org/pub/linux/utils/util- linux/>. util-linux September 2011 COL(1)
All times are GMT -4. The time now is 09:36 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy