Jump to content

Recommended Posts

Posted

I am new to ANSI C and want to use it to write some programs for personal use - and release them into the open source domain.

Where can I find descriptions and syntax for the macros and functions in the thirteen standard header files?

I am an old guy (61) and have used some C before but it has been so long that I have forgotten just about everything I once learned.

I have gleaned a lot from the internet but I am getting tired of looking up each function to learn how to use it.

 

A second question: Is there any way to get a one keystroke input from the keyboard in ANSI C like I could get with getch() in the "old days"?

 

Thanks for your time,

Paul

Posted

There's always wikipedia ANSI C

 

Is there any way to get a one keystroke input from the keyboard in ANSI C like I could get with getch() in the "old days"?

 

It's getchar() now

Posted

There's always wikipedia ANSI C

 

 

 

It's getchar() now

 

Getchar() requires you to hit <enter> after you type the character - that is two keystrokes.

Thanks for the reply but I was asking if there is a way to get a one "single" keystroke entry in ANSI C.

 

I have been using Wikipedia but you have to select each header file for the different functions or macro and then click on it for the definition and syntax.

Going through three different windows, starting with the header file, to get each function's use and syntax.

There has to be somewhere that these are listed by the function or macro name with the syntax and the header file in which they are found, I hope.

 

You may have answered my second question - there is no way to get single key inputs in ANSI C....

 

Thanks for your time,

Paul

Posted (edited)

I've little to no experience with c, but a quick cast around the internet turned up this:

http://www.utas.edu....n/C/CStdLib.htm

Also if you're on some form of unix, chances are you can use 'man stdio', 'man sprintf' or similar to bring up the relevant docs locally.

 

And the prevailing opinion on a good answer to your second question seems to be to use ncurses (if you want to do it fairly portably):

http://www.delorie.c...s_getch.3x.html

http://www.delorie.c...rses-intro.html

 

If you need lighter weight than ncurses for some reason, you'll probably have to do something dependant on the terminal you're using,

http://stackoverflow...-enter-to-be-pr

Outlines a few ways for various platforms.

 

If you're looking for something flashier/more graphical in terms of output, then something like GTK or QT (or insert_OS_here api) would seem appropriate for your input, too.

I think SDL also has some keyboard handling stuff if what you're doing is more game-ey.

Edited by Schrödinger's hat
Posted

ANSI C C89 is what I am using so I can port my software into any C compiler on any system and OS.

I can't add any system, OS or processor specific coding - I have to keep it C89 compliant.

The first link you gave gives a 404 error - a little work and I got it:

http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html

The "L" was left off the end of your link (capitolized for ease of letter determination).

That list is a big help - maybe I can reverse it so it lists it in a manner that will be easier for me, thank you.

 

I know what I am attempting is going to be difficult but in order to be truly portable it has to be that way.

(the software will run on Freedos, Ubuntu 10.10, Mac, and Windoze up to 7)

You should see the code it takes to clear the screen.....!!

 

Thanks again,

Paul

Posted

ANSI C C89 is what I am using so I can port my software into any C compiler on any system and OS.

I can't add any system, OS or processor specific coding - I have to keep it C89 compliant.

The first link you gave gives a 404 error - a little work and I got it:

http://www.utas.edu..../C/CStdLib.html

The "L" was left off the end of your link (capitolized for ease of letter determination).

That list is a big help - maybe I can reverse it so it lists it in a manner that will be easier for me, thank you.

 

Apologies about the missing L.

 

I know what I am attempting is going to be difficult but in order to be truly portable it has to be that way.

(the software will run on Freedos, Ubuntu 10.10, Mac, and Windoze up to 7)

You should see the code it takes to clear the screen.....!!

 

Thanks again,

Paul

 

pcurses/pdcurses/ncurses all have a fairly similar API, and one of them should be available no matter what platform you're on. They should help reduce the amount of code required for portability along with providing features that may otherwise be somewhat cumbersome.

( pdcurses doc here http://pdcurses.sourceforge.net/doc/PDCurses.txt available at http://pdcurses.sourceforge.net or most likely through your package manager )

Combine them with one or two #ifdef statements (if that, PDcurses looks like it's fairly cross-platform out of the box) and you should be right.

The requirement of FreeDOS rules out QT/GTK which are otherwise quite cross-platform (but run on top of a window manager).

 

Out of curiosity, may I ask what you are doing?

Posted

I don't mind you asking, and I will even share. :D

The first program takes input and spits out dimensions for headers for 4 cycle engines (I got tired of doing the math with a calculator).

The second will be a remake of a gas engine anylizer/planner. It will take input and calculate torque at rpm, hp at rpm, volumetric efficiency (average), etc. - I have to remake it because I lost the code 15 years ago.

The third will be a translation of a reloading database and ballistic calculation program. I still have the original code (written in Turbo C++) but I am going to update it a bit and use ANSI C C89.

Then I would like to write some aircraft design/anylizer software.

These are all programs that I want for personal use.

All the programs will be placed into the open source software arena. That way people can modify the programs for their own use and hopefully they will continue to improve over time.

Paul

Posted

doG,

The "Quick Reference Card" is a great addition. Thank you! Even though it doesn't show full syntax and usage it will point me to faster information.

"The Standard C Library Manual" is the GNU library and not ANSI C. It does contain the ANCI C library but it contains much more that is specific to the Unix/Linux operating system. There are a lot of features I like but they don't port well to other OSs.

 

Thank you,

Paul

Posted

I don't mind you asking, and I will even share. :D

The first program takes input and spits out dimensions for headers for 4 cycle engines (I got tired of doing the math with a calculator).

The second will be a remake of a gas engine anylizer/planner. It will take input and calculate torque at rpm, hp at rpm, volumetric efficiency (average), etc. - I have to remake it because I lost the code 15 years ago.

The third will be a translation of a reloading database and ballistic calculation program. I still have the original code (written in Turbo C++) but I am going to update it a bit and use ANSI C C89.

Then I would like to write some aircraft design/anylizer software.

These are all programs that I want for personal use.

All the programs will be placed into the open source software arena. That way people can modify the programs for their own use and hopefully they will continue to improve over time.

Paul

 

Interesting.

Why the requirement for absolute adherence to standards? Do you have some exotic platform it has to run on, or is it just a matter of principle?

If it were just a pragmatic concern (having it run on 99.9% of personal computers), then I would have thought using a couple of platform specific libraries (with similar API), or some cross platform library where other people take care of the hairy details would be the path of least resistance.

I realise nothing can beat the portability and speed of standard C, but everything comes at a cost -- in this case the amount of code you'll need to write. If write once run (almost) anywhere and few hassles are what you are after, have you considered a slightly more modern language? Python and Java have runtimes for almost any platform you can poke a stick at, and you don't even have to think about what you're running on top of unless you want a GUI (with the possible exception of endianness stuff).

They also both have performance within an order of magnitude or so of native code, and a wealth of numeric libraries which are available for most/all platforms they are available for.

(Not that it's the place for a young upstart who probably doesn't even know what he's talking about to tell you what to do; it's just that sometimes we forget/don't realise there are other tools about when we reach for the trusty ol' hammer.)

Posted (edited)

Interesting.

Why the requirement for absolute adherence to standards? Do you have some exotic platform it has to run on, or is it just a matter of principle?

If I had used ANSI C twenty years ago when I wrote the original software - and hung on to the code - I could still run them on all three of my computers today

If it were just a pragmatic concern (having it run on 99.9% of personal computers), then I would have thought using a couple of platform specific libraries (with similar API), or some cross platform library where other people take care of the hairy details would be the path of least resistance.

I have never been one to take the path of least resistance. I guess I am getting worse in my old age (61yo)

 

I realise nothing can beat the portability and speed of standard C, but everything comes at a cost -- in this case the amount of code you'll need to write. If write once run (almost) anywhere and few hassles are what you are after, have you considered a slightly more modern language? Python and Java have runtimes for almost any platform you can poke a stick at, and you don't even have to think about what you're running on top of unless you want a GUI (with the possible exception of endianness stuff).

They also both have performance within an order of magnitude or so of native code, and a wealth of numeric libraries which are available for most/all platforms they are available for.

(Not that it's the place for a young upstart who probably doesn't even know what he's talking about to tell you what to do; it's just that sometimes we forget/don't realise there are other tools about when we reach for the trusty ol' hammer.)

I know (hope?) that ANSI C will be around forever and I am not sure about the others - Java is slow and is likely to get replaced with something faster, Python I just don't know enough about to say if it will be a long lived language, and do either of them have an ANSI standard yet? C is still the number one programming language even after all this time and it is very fast and very powerful. I could use third party libraries but I am going to attempt to do it all in the C89 (ISO 90) code. The worst that can happen is that it won't be what I expect and then I can always add to the libraries as needed.

Most "young upstarts" have more programming skills then I do - I wrote back when Win 3.1 was new and nothing much since so I am just an older newb trying to make my code better now than it was on Turbo C all those years ago. As a mater of fact I am still using Turbo C 2.0 on my DOS system to compile the ANSI C versions.

You have been a real help but I am stubbornly sticking to C89 code, at least for the time being.

 

Paul

Edited by PaulS1950
Posted

I have never been one to take the path of least resistance. I guess I am getting worse in my old age (61yo)

Hahah, I know what you mean.

 

I know (hope?) that ANSI C will be around forever and I am not sure about the others - Java is slow and is likely to get replaced with something faster, Python I just don't know enough about to say if it will be a long lived language, and do either of them have an ANSI standard yet?

Java's reputation for slowness is no longer all that justified. There is (and probably always will be) a lot of overhead, but once you get something started, arguing about performance vs. C is probably splitting hairs. W/ regard to standards, I gather there is a standard for the language, but it's not controlled by any of the standards organisations. With the amount of code (and business code) written for Java, I doubt it's going to go anywhere, and any compatibility breaking changes would result in mass migration to one of the non-official implementations.

 

Python has a ways to catch up for most applications. Concerns about bit rot are probably fairly valid here, it's a young language and is still changing (major version numbers will break code). There seems to be fairly wide (and increasing) support for python among the scientific community, so I expect it to last a long time and wouldn't be surprised if it becomes the next fortran.

 

C is still the number one programming language even after all this time and it is very fast and very powerful. I could use third party libraries but I am going to attempt to do it all in the C89 (ISO 90) code. The worst that can happen is that it won't be what I expect and then I can always add to the libraries as needed.

Most "young upstarts" have more programming skills then I do - I wrote back when Win 3.1 was new and nothing much since so I am just an older newb trying to make my code better now than it was on Turbo C all those years ago. As a mater of fact I am still using Turbo C 2.0 on my DOS system to compile the ANSI C versions.

You have been a real help but I am stubbornly sticking to C89 code, at least for the time being.

 

By all means. I was just checking that you were aware of/had considered the alternatives. If your goal is for it to work anywhere and any time, I can't think of a better solution (with the possible exception of forth for the anywhere bit. Then again, even your fridge or kettle probably have C compilers written for them these days). If your goal had just been for it to work on most current systems, then one of my suggestions may have been worthwhile.

Posted

Thanks to everyone. This has been an excellent conversation. It has caused me to look at some added libraries that I may NEED to use but for the time being I will stay with ANSI C (C-89) for my coding. I also looked up some things from the distant past like using Ascii codes and the printf() statements but I found that there are too many places that Ascii is no longer a standard in use. It has been good for me and a very fast learning curve on the confines of pure ANSI standard coding. I think I will enjoy it.

 

Paul

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.