Thread: clerol function in xcode

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    2

    clerol function in xcode

    Hi all,

    I'm new to programming and is currently learning C programming. My lecturer is using Borland C which has the conio.h header file.

    Im using xcode on my mac, and I need to use the clerol() function which is available in Borland C but not in xcode. The function basically clears end line in text window in text mode.

    Does anyone knows if there is a similar function in xcode?

    Thank you all.

    e1504

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by e1504 View Post
    Im using xcode on my mac, and I need to use the clerol() function which is available in Borland C
    Are you sure? That gives me 3 results in Google, and that includes this thread.

    Can you explain in a more clear manner what the function does.

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    357
    I think you mean clreol() ("CLeaR to End Of Line").

    You can maybe install a curses library (ncurses) and use that (possibly with a few changes) instead of Borland's library.

    The bestest option is to convince your teacher to upgrade to a more modern compiler and stick to Standard defined functions

  4. #4
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    If you mean cleareol() or cleol(), which clear parts of the screen (lines), they can be replaced with ANSI (CSI) codes, which work in Windows, Mac, and Linux terminals (except for very dumb ones). For the CSI character mentioned in the tables, use ASCII ESC and [, "\033[".

    For example, to move to second row, fifth column, you can use
    Code:
    printf("\033[2;5H");
    To clear the line starting at the fifth column on the second row, while keeping current cursor position, you can use
    Code:
    printf("\033[s");    /* Save cursor position */
    printf("\033[2;5H"); /* Move to second row, fifth column */
    printf("\033[0K");   /* Clear to the end of the row */
    printf("\033[u");    /* Restore cursor position */
    and you can of course combine the commands, too:
    Code:
    printf("\033[s\033[2;5H\033[0K\033[u"); /* Clear the second row, starting from column 5, to the end of the row. */
    Colors and some other attributes are available, too.

    How these map to cleareol() and friends, I don't know and do not care. That toolkit is completely irrelevant; nobody actually uses it anymore. Except your instructor, I guess.

    It just boggles my mind your instructor would use such an ancient, unsupported toolkit, when better, free (no cost and libre), cross-platform alternatives are available. Personally, I'd fire such an instructor and find a better one. As it is now, you are wasting time learning irrelevant stuff you will not be able to ever use in real life. Why waste limited resources?

    Why not use something like GTK+ and GCC, and do fully interactive windowed applications? Both are available for download on all three major platforms, and GTK+ is C (NOT C++), and provides a much more realistic environment. For the simple stuff like Hello world, you only need about a dozen lines of code!

    Or, if you want to do text-mode stuff, why not provide a minimal set of text-mode functions that emit ANSI CSI codes, or even a full Curses library? It'd work on all three major architectures, and they're still in use in console stuff.

  5. #5
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    ncurses, requires a separate group of functions related to that library, init the screen in curses mode etc.

    You could try ansi escape sequences, try if this does the same.

    Code:
    #define clreol() printf("%s", "\033[0J")
    If so you could replace the #include coneo.h bit with that #define.

  6. #6
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Or run Borland C in an emulated environment.

    And, yeah, Borland is ancient now, but a lot of instructors were brought up on it and don't know any other way. You only have to watch these forums to see its popularity among that class of educator. If we sacked them all, there'd be nobody learning programming at all... :-)

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    2
    Hi all,

    Thanks for the reply.

    Yeah. Indeed, what I meant is the "clear to end of line" function. As I am really new to C programming (my 5th lesson), I really do not quite understand what you guys are discussing earlier :x Pardon me... But I've googled and I think what the function does is similar to what is described here (clreol function >> conio.h >> Clears end line in text window | C Programming : Header File | C : Header File Functions, Header File : conio.h Reference).

    The part of the code Im referring to is as per below


    default:
    move(25,18);
    clreol(); //this is the part whereby xcode says Implicit declaration of function
    printf("Invalid choice, Please Enter between 1 to 6");
    getchar();

    I've been googling but to no avail as to how to solve this... Some stuff my instructor taught is also weird or wrong. I can't use clrscr() and must use system("clear")... and I can't use getch() but must use getchar().

    So i was wondering, instead of all the above more complicated solutions which I don't really understand (so sorry about it), is there any more direct way? Like is there an equivalent to clreol() in xcode?

    Thank you all sincerely



  8. #8
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by e1504 View Post
    clreol();
    is same as printf("\033[K"); fflush(stdout);

    Quote Originally Posted by e1504 View Post
    I can't use clrscr() and must use system("clear")
    Both are equivalent to printf("\033[H\033[2J"); fflush(stdout);

    If you want to have the code "just work", add
    Code:
    static void clreol(void) { printf("\033[K"); fflush(stdout); }
    static void clrscr(void) { printf("\033[H\033[2J"); fflush(stdout); }
    near the top of your code, just after the #include lines, and use clreol() and clrscr(). If your instructor complains, just before handing them replace the two lines with
    Code:
    static void clrscr(void) { system("clear"); }
    I'm very sorry your instructor is making you learn stuff you won't be able to use in practice.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by e1504 View Post
    Code:
    default:
    move(25,18);
    clreol();      //this is the part whereby xcode says Implicit declaration of function
    printf("Invalid choice, Please Enter between 1 to 6");
    getchar();
    If that move function moves the cursor on the screen, then there is no standard C in there apart from the default label and printf. clreol() wouldn't make much sense unless you have text below your cursor which really can't happen in normal terminal mode with only standard C.
    Last edited by Subsonics; 10-10-2012 at 09:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Xcode
    By Zach Sisk in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2012, 05:29 AM
  2. Replies: 2
    Last Post: 07-13-2011, 06:50 AM
  3. difference between IDE and SDK (VS and Xcode)
    By c_lady in forum Tech Board
    Replies: 4
    Last Post: 05-14-2010, 06:19 PM
  4. getline under Xcode on a Mac
    By Dino in forum C++ Programming
    Replies: 7
    Last Post: 12-26-2009, 11:37 AM
  5. mac os x xcode
    By magus2500x in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2005, 12:12 AM

Tags for this Thread