Limiting printf area

This is a discussion on Limiting printf area within the C Programming forums, part of the General Programming Boards category; Hello! Suppose I draw a frame round the screen, using ascii table symbols and the next thing I want to ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    16

    Limiting printf area

    Hello! Suppose I draw a frame round the screen, using ascii table symbols and the next thing I want to do is printf different text, of course limiting the area, so that my text wouldn't be printed across these frame borders. Is it possible in C to tell to print everything within some limits? Surely gotoxy at each printf isn't the solution?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    What you want to do can only be done using a non-standard library like ncurses. It cannot be done using just printf().
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    16
    It seemed so easy with includes in php or even frames in html, shame that C doesn't allow this.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    C is older than both of those. It does allow it, there's just no standard way to do it, because there are no "standard" screens or terminals.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by nowber View Post
    Hello! Suppose I draw a frame round the screen, using ascii table symbols and the next thing I want to do is printf different text, of course limiting the area, so that my text wouldn't be printed across these frame borders. Is it possible in C to tell to print everything within some limits? Surely gotoxy at each printf isn't the solution?
    Sometimes, people ask "Why use that old Turbo C/C++ ?", and I just smile:

    Code:
    window   Defines active text-mode window.
    
     Syntax:
       void window(int left, int top, int right, int bottom);
    
    The top left corner of the screen is (1,1).
    
     Prototype in:
     conio.h
    
     Remarks:
    window defines a text window onscreen. If the coordinates are in any way
    invalid, the call to window is ignored.
    
      left and top are the screen coordinates
       of the upper left corner of the window.
    
      right and bottom are the screen
       coordinates of the lower right corner.
    
       The minimum size of the text window is one
       column by one line. The default window is
       full screen, with these coordinates:
    
      80-column mode:    1,1,80,25
      40-column mode:    1,1,40,25
    
     Return Value: None.
    
     Portability:
    window works with IBM PCs and compatibles only.
    
    A corresponding function exists in Turbo Pascal.
    
     See Also:
      clreol    delline        gotoxy     puttext
      clrscr    gettextinfo    insline   textmode
    
     Example:
     #include <conio.h>
    
     int main(void)
     {
    
        window(10,10,40,11);
        textcolor(BLACK);
        textbackground(WHITE);
        cprintf("This is a test\r\n");
    
        return 0;
     }
    Note that Turbo C ver. 1.01 had "int main()", before K&R's "The C Programming Language".

    Lacking conio.h's help, you can still print inside a window, just as you can print up any columns, in C.

    You just need variables for things like lmargin, rmargin, toprow, botrow, to define the left margin, right margin, top row, bottom row, etc.

    So in a function, you send it the address of your char array you want printed, and it will handle it from there. It's not as nice as window, but it can be done easily.
    Last edited by Adak; 10-26-2009 at 03:17 PM.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Quote Originally Posted by Adak View Post
    Turbo C nonsense
    Or you can just use ncurses. This gives you the added benefit of using a real, working compiler at the same time. If you are running on Windows, then pdcurses should do it.
    bit∙hub [bit-huhb] n. A source and destination for information.

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Adak View Post
    Sometimes, people ask "Why use that old Turbo C/C++ ?", and I just smile:
    Or you could just use Pascal!


    Quzah.
    Hope is the first step on the road to disappointment.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by quzah View Post
    Or you could just use Pascal!


    Quzah.
    I never liked Pascal, but was helping my nephew with his programming class and of course, they used it.

    The Borland Pascal compiler was like *lightning*, even on large chess programs. Even 15 years later, I've never used a faster compiler. (iirc it incrementally pre-compiled as much as possible, in the background).

    All those writeline commands -- ssshhh! Drive you right around the bend.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. IF CONDITION plese help
    By birumut in forum C Programming
    Replies: 12
    Last Post: 03-06-2009, 09:48 PM
  2. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  3. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  4. Simple C question: user input to repeat a loop
    By evernaut in forum C Programming
    Replies: 2
    Last Post: 11-18-2006, 09:23 AM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 11:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21