LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-04-2005, 10:45 AM   #1
xrado
Member
 
Registered: Dec 2004
Distribution: Zenwalk/Slackware
Posts: 98

Rep: Reputation: 15
program console output using C


lets say i print this out ...

printf("S1 : %d\n", s1);
printf("S2 : %d\n", s2);
printf("S3 : %d\n", s3);

now how do i print them out again, without using new lines
i just wana update (again and again) values (s1-s3) printed out befour on same screen location

i hope you understand me
 
Old 04-04-2005, 12:25 PM   #2
Duo
LQ Newbie
 
Registered: Nov 2004
Distribution: Slackware 10.1
Posts: 22

Rep: Reputation: 15
Hmm? How do you mean? Like, should output resemble :

S1 : blah S2 : blah S3 : blah

?

or do you want to just use one printf to output them?

I think

printf ("S1 : %d\t S2 : %d \t S3 : %d\n", s1, s2, s3);

should do it. presumably being printed out again and again as part of a loop?

sorry if I have misunderstood the question. =/
 
Old 04-04-2005, 12:52 PM   #3
mcosta
Member
 
Registered: Jan 2005
Location: Spain
Distribution: Debian
Posts: 44

Rep: Reputation: 15
For complex operations on screen (not a simple stream) you need, for example, aalib. The function to move to a position is aa_gotoxy(). But you need a *aa_context, you can create it with aa_autoinit().
 
Old 04-04-2005, 01:39 PM   #4
xrado
Member
 
Registered: Dec 2004
Distribution: Zenwalk/Slackware
Posts: 98

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Duo
Hmm? How do you mean? Like, should output resemble :

S1 : blah S2 : blah S3 : blah

?

or do you want to just use one printf to output them?

I think

printf ("S1 : %d\t S2 : %d \t S3 : %d\n", s1, s2, s3);

should do it. presumably being printed out again and again as part of a loop?

sorry if I have misunderstood the question. =/

no, i dont want new values to be printed in new lines
i just want update the line i printed once

thx anyway
 
Old 04-04-2005, 01:43 PM   #5
__J
Senior Member
 
Registered: Dec 2004
Distribution: Slackware, ROCK
Posts: 1,973

Rep: Reputation: 46
something like this?

Code:
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv)
{

    int input1, input2;
    input1 = 10;
    input2 = 20;
    int counter = 0;

    while ( counter <= 100 ) {
        fprintf(stderr, "\r");
        fprintf(stderr, "#1: %d   #2: %d", input1++, input2++);
        sleep(1);
        counter++;
    }
    printf("\n");
    return 0;
}

Last edited by __J; 04-04-2005 at 02:13 PM.
 
Old 04-04-2005, 02:48 PM   #6
xrado
Member
 
Registered: Dec 2004
Distribution: Zenwalk/Slackware
Posts: 98

Original Poster
Rep: Reputation: 15
yes, thats it..thx!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
C function to execute a program and return the output of the program ryan.n Programming 4 08-14-2004 10:11 PM
How to disable console output kamel Programming 2 06-02-2004 01:41 PM
noob needs help with console output (c++) shadow.blue Programming 7 04-19-2004 05:24 PM
Console output to X? dcm1878 Linux - Software 4 04-23-2003 08:07 PM
Long console output Loke Linux - Newbie 1 02-26-2003 06:35 AM


All times are GMT -5. The time now is 09:42 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration