Are clrscr(); and system("cls"); same?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AmberJain
    Recognized Expert Contributor
    • Jan 2008
    • 922

    Are clrscr(); and system("cls"); same?

    Hello,

    What is the difference between -------->

    1. clrscr(); // defined in various header files

    2. system("cls"); //available in stdio.h in bloodshed dev c++

    Well, if there are no differences, then can we use them interchangebly?

    PLUS,

    I saw a bit slower execution of program (I'm not sure about this fact) while execution of my code that contained system("cls"); than clrscr();. Does that implies that system("cls"); is slower in execution in clrscr();? If yes, what's the reason for it?

    THANKS TO EVERYONE IN ADVANCE........ ...

    =============
    [AmbrNewlearner]
    =============
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    The system() function fires up an entire shell or command line interpreter, whatever
    is available on your system and passes its argument to it. That may take some
    time to complete. I don't know what your clrscr() function does but it probably
    calls some highly system dependent functionality.

    kind regards,

    Jos

    Comment

    • AmberJain
      Recognized Expert Contributor
      • Jan 2008
      • 922

      #3
      Originally posted by JosAH
      The system() function fires up an entire shell or command line interpreter, whatever
      is available on your system and passes its argument to it. That may take some
      time to complete. I don't know what your clrscr() function does but it probably
      calls some highly system dependent functionality.

      kind regards,

      Jos
      Well, clrscr() simply clears the screen (similar to "cls" command for DOS).

      One more question,

      I have recently switched from Borland Turbo C++ 3.0 (IDE + compiler) to Bloodshed Dev c++ (IDE) PLUS gcc (compiler).
      Now my question is as follows---->
      Can I use the include (or header files) available with Turbo C++ 3.0 in C programming using [Bloodshed Dev C++] + [gcc] combination.

      THANKS IN ADVANCE....

      =============
      [AmbrNewlearner]
      =============

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by ambrnewlearner
        Well, clrscr() simply clears the screen (similar to "cls" command for DOS).
        Yes, but the question was (and is) *how* does it do it? I briefly explained how that
        system("cls") managed to clear the screen on a Windows machine (it'll fail
        horribly on a Linux machine without any precautions) but we still don't know
        how the clrscr() function accomplishes it. So the problem is not *that* it does
        what you want, the problem is *how* does it do it.

        Originally posted by ambrnewlearner
        One more question,

        I have recently switched from Borland Turbo C++ 3.0 (IDE + compiler) to Bloodshed Dev c++ (IDE) PLUS gcc (compiler).
        Now my question is as follows---->
        Can I use the include (or header files) available with Turbo C++ 3.0 in C programming using [Bloodshed Dev C++] + [gcc] combination.
        No, because those header files might expose certain structures used by a
        library of vendor X; a library of vendor Y might use entirely different structures.

        kind regards,

        Jos

        Comment

        • AmberJain
          Recognized Expert Contributor
          • Jan 2008
          • 922

          #5
          THANKS JosAH.......

          Originally posted by JosAH
          Yes, but the question was (and is) *how* does it do it? I briefly explained how that
          system("cls") managed to clear the screen on a Windows machine (it'll fail
          horribly on a Linux machine without any precautions) but we still don't know
          how the clrscr() function accomplishes it. So the problem is not *that* it does
          what you want, the problem is *how* does it do it.
          If you find something about this in future, please tell me.
          Originally posted by JosAH
          No, because those header files might expose certain structures used by a
          library of vendor X; a library of vendor Y might use entirely different structures.

          kind regards,

          Jos
          OK, THANKS again...

          =============== ==
          [AMBRNEWLEARNER]
          =============== ==

          Comment

          • oler1s
            Recognized Expert Contributor
            • Aug 2007
            • 671

            #6
            Can I use the include (or header files) available with Turbo C++ 3.0 in C programming using [Bloodshed Dev C++] + [gcc] combination.
            The only thing you are guaranteed is the implementation of the standard library. So only expect the header files for the standard library. There might be compiler specific header files, but as the phrase suggests, these are compiler specific.

            Comment

            • AmberJain
              Recognized Expert Contributor
              • Jan 2008
              • 922

              #7
              Originally posted by oler1s
              The only thing you are guaranteed is the implementation of the standard library. So only expect the header files for the standard library. There might be compiler specific header files, but as the phrase suggests, these are compiler specific.
              Thanks oler1s......... .

              ============
              AmbrNewlearner
              ============

              Comment

              • oler1s
                Recognized Expert Contributor
                • Aug 2007
                • 671

                #8
                (In response to Josah’s comment about not knowing how clrscr() works) If you find something about this in future, please tell me.
                I think you fail to understand what Josah is saying. clrscr is not part of any open standard. We cannot know how it works because it is compiler proprietary.

                Comment

                • AmberJain
                  Recognized Expert Contributor
                  • Jan 2008
                  • 922

                  #9
                  Originally posted by oler1s
                  I think you fail to understand what Josah is saying. clrscr is not part of any open standard. We cannot know how it works because it is compiler proprietary.
                  Yeah, I misinterpreted JosAH.
                  But I now understand your point.

                  Thanks JosAH and oler1s......

                  ============
                  AmbrNewlearner
                  ============

                  Comment

                  • Erick Oigara

                    #10
                    system("cls")wo rks in the same way as clrscr(),but the former seems slower than the latter i strongly advice to use the better option(quicker one)

                    Comment

                    Working...