C\C++: why ANSI C don't have GotoXY and others?

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1310 Views - Last Post: 19 April 2019 - 11:00 AM Rate Topic: ***** 1 Votes

#1 Cambalinho   User is offline

  • D.I.C Addict

Reputation: 2
  • View blog
  • Posts: 783
  • Joined: 04-March 12

C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 12:48 PM

The C\C++ are more Console Programming Languages, but why the ANSI don't have clrscr(), gotoxy(), setcolor() and others Console functions?
(the ASCII codes(for change cursor position and text colors), using printf(), don't work on all IDE\compilers)

This post has been edited by Cambalinho: 18 April 2019 - 12:49 PM

Is This A Good Question/Topic? 1
  • +

Replies To: C\C++: why ANSI C don't have GotoXY and others?

#2 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6881
  • View blog
  • Posts: 23,344
  • Joined: 05-May 12

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 01:13 PM

At the time C created, it was also meant to run on machines which only had line printers and teletypes. It didn't make much sense at that time to have those console manipulation functions.

Of course modern C++ now seems to be adapting to modern machines. Perhaps the newer C++ language standard should also include some addressable console functions.
Was This Post Helpful? 2
  • +
  • -

#3 jimblumberg   User is offline

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 01:15 PM

Probably several reasons. For example do you realize that C doesn't assume that there is any console?

Do you realize that there are (were) consoles that did not have the ability to magically position the cursor (anywhere other than the beginning of a line) or clear the screen?

Do you realize that if you googled your question you would find thousands of links explaining the problem?


For example: https://www.quora.co...phics-libraries and http://www.stroustru...bs_faq.html#gui to show but two of the thousands.


Jim
Was This Post Helpful? 2
  • +
  • -

#4 Cambalinho   User is offline

  • D.I.C Addict

Reputation: 2
  • View blog
  • Posts: 783
  • Joined: 04-March 12

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 01:40 PM

seems like to say: C\C++ it's a language, but the Console it's a library....
but Math it's a header file(more or less like a library)...
but i get the point.... but using C\C++ can we create Our own gotoxy() using ANSI code?
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6881
  • View blog
  • Posts: 23,344
  • Joined: 05-May 12

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 01:46 PM

You can, but you are presuming that the console you will be running on supports the ANSI escape codes, or you have code that detects the system you are running on and calls the appropriate console APIs, be it Windows Console APIs, ANSI escape codes, or xterm, etc. Unless this really fascinates you, you maybe better off just using the curses lib and move on to the more interesting bits of programming.
Was This Post Helpful? 1
  • +
  • -

#6 jimblumberg   User is offline

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 01:50 PM

Quote

but using C\C++ can we create Our own gotoxy() using ANSI code?

Yes, you can use system specific "functions" to access the hardware and write your own gotoxy() functions.

Jim
Was This Post Helpful? 1
  • +
  • -

#7 Cambalinho   User is offline

  • D.I.C Addict

Reputation: 2
  • View blog
  • Posts: 783
  • Joined: 04-March 12

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 02:50 PM

"Yes, you can use system specific "functions" to access the hardware and write your own gotoxy() functions."
what are them? do you mean assembler or it's anotherthing?
Was This Post Helpful? 0
  • +
  • -

#8 jimblumberg   User is offline

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 02:54 PM

What operating system are you concerned with?

On Windows you would use some of the Windows API functions, on Linux you would use the termio functions. On a system with no operating system you would need to use system specific calls, consult your system documentation.

Jim
Was This Post Helpful? 1
  • +
  • -

#9 Cambalinho   User is offline

  • D.I.C Addict

Reputation: 2
  • View blog
  • Posts: 783
  • Joined: 04-March 12

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 03:01 PM

i use windows... but been more Multi Operation System, better ;)
Was This Post Helpful? 0
  • +
  • -

#10 jimblumberg   User is offline

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 08:15 PM

There is no one solution for all platforms you wish to support, if you want multi-platform you will need to write a solution for each platform and conditionally use the proper solution for the given platform.


Jim
Was This Post Helpful? 1
  • +
  • -

#11 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2339
  • View blog
  • Posts: 4,449
  • Joined: 30-May 10

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 18 April 2019 - 10:53 PM

View PostCambalinho, on 18 April 2019 - 10:01 PM, said:

i use windows... but been more Multi Operation System, better ;)/>

https://en.wikipedia.org/wiki/Ncurses
https://en.wikipedia.org/wiki/PDCurses

> what are them? do you mean assembler or it's anotherthing?
https://docs.microso...nsole-functions
Was This Post Helpful? 1
  • +
  • -

#12 Cambalinho   User is offline

  • D.I.C Addict

Reputation: 2
  • View blog
  • Posts: 783
  • Joined: 04-March 12

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 19 April 2019 - 03:45 AM

i belive testing the Operation System it's a pre-processor code.... but how can i test it?
can you share 1 sample just using 1 'if' and 1 'else'?
Was This Post Helpful? 0
  • +
  • -

#13 Salem_c   User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 2339
  • View blog
  • Posts: 4,449
  • Joined: 30-May 10

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 19 April 2019 - 04:56 AM

Either of these would be good places to start.
https://sourceforge....edef/wiki/Home/
https://github.com/boostorg/predef
Was This Post Helpful? 1
  • +
  • -

#14 Cambalinho   User is offline

  • D.I.C Addict

Reputation: 2
  • View blog
  • Posts: 783
  • Joined: 04-March 12

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 19 April 2019 - 05:05 AM

like these:
#if defined(_WIN16)
          SetWindowPos(....)
#else
      LinuxWindowSize(...)
#endif

ok... the Linux function is a wrong name(but can be created).... but i belive these is the way, right?
Was This Post Helpful? 0
  • +
  • -

#15 jimblumberg   User is offline

  • member icon

Reputation: 5726
  • View blog
  • Posts: 17,531
  • Joined: 25-December 09

Re: C\C++: why ANSI C don't have GotoXY and others?

Posted 19 April 2019 - 08:08 AM

The first thing I suggest you do is write your different functions to solve the issue for one platform. Once you have the functions working for one platform, you can do the same for the other platform. You will then use macro hacks or possibly namespaces to combine the functions for your projects that require this functionality. However, it may be easier to use existing frameworks instead of trying to do it yourself.


Jim
Was This Post Helpful? 2
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2