GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Dec-2004, 08:43
Jags's Avatar
Jags Jags is offline
New Member
 
Join Date: May 2004
Posts: 13
Jags is on a distinguished road

Print a character without moving cursor


is it possible to print a character without moving the cursor to the next position ???

i am trying to create a fullscreen-BOX, but as soon as the bottom-right character is printed the screen shifts downward by one line.

help me out guys !!!
  #2  
Old 06-Dec-2004, 09:27
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Jags
is it possible to print a character without moving the cursor to the next position ???

i am trying to create a fullscreen-BOX, but as soon as the bottom-right character is printed the screen shifts downward by one line.

help me out guys !!!

What compiler/operating system?

Many windows compilers have a function called getch(), prototyped typically in <conio.h>.

This is a non-standard C library function, and its use is may not be portable to other platforms.

For linux/unix platforms, here is an example of an equivalent function that works for me:

http://www.gidforums.com/t-3386.html



Regards,

Dave
  #3  
Old 06-Dec-2004, 09:59
Jags's Avatar
Jags Jags is offline
New Member
 
Join Date: May 2004
Posts: 13
Jags is on a distinguished road
Quote:
Originally Posted by davekw7x
What compiler/operating system?

Many windows compilers have a function called getch(), prototyped typically in <conio.h>.

This is a non-standard C library function, and its use is may not be portable to other platforms.

For linux/unix platforms, here is an example of an equivalent function that works for me:

http://www.gidforums.com/t-3386.html



Regards,

Dave

the complier that i am using is Turbo C++ version 3.0 and it's DOS based complier

the function getch() that you are refering to is available in my complier but it is used for getting an INPUT from console
[i.e. it simply gets a character from console but does not echo to the screen]

but i want to OUTPUT a character to console

getch() cannot solve my purpose
  #4  
Old 06-Dec-2004, 10:15
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Jags
the complier that i am using is Turbo C++ version 3.0 and it's DOS based complier

the function getch() that you are refering to is available in my complier but it is used for getting an INPUT from console
[i.e. it simply gets a character from console but does not echo to the screen]

but i want to OUTPUT a character to console

getch() cannot solve my purpose

I'm sorry, I didn't read your request very carefully. Somehow my poor little peanut-brain registered a request to get user input without echoing it.
I don't know of any standard (or non-standard, for that matter) output functions useable with Turbo C++ that don't advance the cursor. Pre-Windows NT operating systems allowed direct writing to console memory, but modern operating systems vigorously guard against such actions.

Regards,

Dave
  #5  
Old 06-Dec-2004, 10:43
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by Jags
is it possible to print a character without moving the cursor to the next position ???

i am trying to create a fullscreen-BOX, but as soon as the bottom-right character is printed the screen shifts downward by one line.

help me out guys !!!
No. The OS will output it's prompt, which will cause a newline to appear. The best you can hope for is screen height - 1 unless you stop printing immediately after the last character, and don't exit the program. If this is acceptable, just don't output the last '\n'
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #6  
Old 06-Dec-2004, 11:21
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,217
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by WaltP
No. The OS will output it's prompt, which will cause a newline to appear. The best you can hope for is screen height - 1 unless you stop printing immediately after the last character, and don't exit the program. If this is acceptable, just don't output the last '\n'

Sorry, Walt, the output functions (printf(), putchar(), etc) always result in an incremented cursor.

CPP / C++ / C Code:
#include <stdio.h>

int main()
{
  int rows = 25;
  int cols = 80;
  int i;

  for (i = 1; i < rows; i++) {
    printf("%2d\n", i);
  }
  for (i = 1; i <= cols; i++) {
    putchar((i%10)+'0');
    /*printf("%c", (i%10)+'0'); */ /* try this instead of putchar() */
  }
  for(;;) /* enter ctrl-c to exit the program */
    ;
  return 0;
}

(I used the for(;;); stuff to make sure that something else, like getchar(), wouldn't be suspected of affecting the output.)


Regards,

Dave
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Conversion: Binary, Decimal, Hexadecimal WaltP C Programming Language 1 10-May-2006 07:49
Can someone check to see if my program is correct tommy69 C Programming Language 2 12-Apr-2004 21:36
Guestbook error BobbyDouglas Web Design Forum 1 16-Oct-2003 23:17

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:19.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.