tired of typing same line over and over again....

This is a discussion on tired of typing same line over and over again.... within the C Programming forums, part of the General Programming Boards category; Hello! I am using the lines: printf("\n\n"); system("cls"); system("pause"); alot when im coding me school projects and i was wondering ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    15

    tired of typing same line over and over again....

    Hello!

    I am using the lines:

    printf("\n\n");
    system("cls");
    system("pause");

    alot when im coding me school projects and i was wondering if its possible to make like alias to those lines.... It would be sweet if i could write:

    line
    cls
    pause

    instead of repeating the same lines over and over again....

    Tyvm!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,962
    You could write a function.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    bha hahah yes OFC!!!!

    tyvm for help hehe!

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Or a macro.


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

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    41
    Quote Originally Posted by ingenting View Post
    Hello!

    I am using the lines:

    printf("\n\n");
    system("cls");
    system("pause");

    alot when im coding me school projects and i was wondering if its possible to make like alias to those lines.... It would be sweet if i could write:

    line
    cls
    pause

    instead of repeating the same lines over and over again....

    Tyvm!
    Code:
    #include <stdio.h>
    
    #define pause system("pause")
    
    int main()
    {
    pause;
    pause;
    pause;
    return 0;
    }
    or if you really want to not have a bunch of defines in the top of your source you can make another file and include it.
    Code:
    //personalize.h
    
    #define line printf("\n\n")
    #define cls system("cls")
    #define pause system("pause")
    then do:
    Code:
    #include <stdio.h>
    #include "personalize.h"
    
    int main()
    {
    pause;
    pause;
    pause;
    line;
    cls;
    return 0;
    }
    Last edited by strickyc; 05-10-2009 at 09:30 PM.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Typically, you don't #include .c files. You #include header files.


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

  7. #7
    Registered User
    Join Date
    Apr 2009
    Posts
    41
    Quote Originally Posted by quzah View Post
    Typically, you don't #include .c files. You #include header files.


    Quzah.
    (opps) was typing it fast(opps)

  8. #8
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    Those macros seems nice!

    Tyvm for help guys!

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,962
    Quote Originally Posted by ingenting
    Those macros seems nice!
    If you do want to use them, use fully capitalised names instead, as is the convention for macros.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I personally prefer functions over macros every time. In this case, the functions are relatively simple, so the compiler may inline them, so there is no overhead. And there are no variables involved, so there's no benefit from that perspective on using macros.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    The larch
    Join Date
    May 2006
    Posts
    3,573
    ...so there is no overhead...
    Overhead in pausing a program? Besides, system("pause") itself seems to have quite a lot of overhead, not that you'd care too much.
    Last edited by anon; 05-11-2009 at 03:19 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by anon View Post
    Overhead in pausing a program? Besides, system("pause") itself seems to have quite a lot of overhead, not that you'd care too much.
    I actually meant overhead in code-size, rather than in execution time - sure, hitting a key for "pause" will eat a lot of CPU and time both.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    He means there's no overhead in the actual call to the function. ie:
    Code:
    #define BLAH ...
    
    void blah( void )
    {
        ...pause...
        ...printstuff...
    }
    The overhead in calling function 'blah' instead of using macro BLAH. Not the overhead with system( "pause" ).

    [edit] Beaten to it. [/edit]

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

  14. #14
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,158
    Let's see... printf() ends up hitting the operating system, which scrolls a terminal line buffer, which results in probably several hundred thousand pixels being redrawn. Then a call to system, which involves creating a process. Then another call to system to create a pause...

    Somehow, I don't think function call overhead is a consideration here.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by brewbuck View Post
    Let's see... printf() ends up hitting the operating system, which scrolls a terminal line buffer, which results in probably several hundred thousand pixels being redrawn. Then a call to system, which involves creating a process. Then another call to system to create a pause...

    Somehow, I don't think function call overhead is a consideration here.
    Indeed. If it's used OFTEN, it creates bigger code (but most likely, the overall code is small enough that it doesn't matter ANYWAYS). [And of course, calling printf instead of a simple function may actually create MORE code - so that's an argument for NOT using macros].
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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