Pelles C forum

Pelles C => General discussions => Topic started by: colepc on March 19, 2015, 03:01:05 am

Title: Writing C code is fun and can be addictive
Post by: colepc on March 19, 2015, 03:01:05 am
I probably started using C some 25 years ago as a hobby. I was able to use that knowledge later for some work related assignments. The last time I used C was perhaps 10 years ago. I am now retired and recently my interest in C has rekindled. My first problem was finding a C compiler that worked on my 64-bit computer which uses Windows 7.  Pelles C allowed me to do that.

My first Pelles C programs were command line programs that encoded and decoded files. I doubt I'll ever actually use these programs for spy work but it was fun converting spreadsheets into gibberish and then back again into working files. It uses what is called "one-time pad" encryption where "random" values are used for encoding and the same "random" values are used for decoding. Instead of using kilobytes of straight line "random" values for large files, I use 240 "random" values that can create over 250 million "random" values. Rightly or wrongly, I figure adding five "random" numbers also creates a "random" number as long as the adding of the same five "random" values is never repeated.   

One of my projects was redeveloping a serial port diagnostic tool that could run on my current computer. I had created one many years ago but that program will not work on my 64-bit computer. My serial port diagnostic tool uses color codes for displaying non-ASCII characters so I couldn't use a command line program. Color can be done in Windows so I thought this could be a great way to learn Win32.  What is interesting is that after creating this program I cannot possibly test it using a serial port as my computer does not have one (serial ports are old technology and are not used much anymore). Even so I used Win32 to create a better diagnostic tool then I had previous. All that remains is adding the serial port interface logic and maybe someday I'll do that.

What I learned about Win32 programs is that they are 40% fun and 60% frustration (my command line programs are 80% fun and 20% frustration). For example I created a command line program calculating averages, extreme spread, average deviation, and standard deviation for bullet speeds and I did that in under a day. It was a simple program that used Notepad to enter values that are saved to a file and my program reads that file to create the statistics. I decided to do a similar project using Win32 so I could enter the values within the program (no longer using Notepad). So far I have spent 10 days on this project (I have a few other features I want to add). The point is that Win32 programs are more complicated and can take much longer to develop but they can have many rich features not available with command line programs.

Some other projects I have completed (all command line programs):
* A program that tells the ASCII and hex values of files (useful for seeing the data entered into files after they are created).
* A program that tells where long lines are located in a text file (useful if the long lines are all white space).
* A program that gives statistics about file data (used to detect how "random" my encoded files actually are).
* A program that converts "random" file values into ASCII hex values for adding to a C program. I use these "random" values as initialization values for arrays within my encode and decode programs.

Writing C code can really be addictive. After I complete a project I often feel like I just came down from a high and need another fix. I cannot always think of another project that sounds like fun. Tell me about some of your fun projects.
 
Title: Re: Writing C code is fun and can be addictive
Post by: jj2007 on March 19, 2015, 03:34:03 am
Writing C code can really be addictive.

You haven't tried assembler ;-)

On my project list are mostly Win32 applications:
- my own editor
- an organiser for my daily duties
- a tiny app that requests train departure times
... etc
Title: Re: Writing C code is fun and can be addictive
Post by: DMac on March 19, 2015, 04:21:56 pm
I've averaged about one hobby project a year for the last 8 or nine years.  Mostly windows controls.  For the latest project I rewrote an instrument screen capture application that I first developed about 9 years ago.  This time around I encapsulated the HPGL parser/renderer for easy re-use and employed my Property Grid control to give the user access to the virtual plotter's parameters.  It and all of my other Pelle's C projects can be found in the User Contributions section of this forum.
Title: Re: Writing C code is fun and can be addictive
Post by: czerny on March 19, 2015, 04:50:45 pm
Tell me about some of your fun projects.
What about C libraries for some usefull standard algorithmes, say linked lists or binary trees. They can be used both from console and windows applications.
Title: Re: Writing C code is fun and can be addictive
Post by: Grincheux on March 19, 2015, 06:16:09 pm
JJ2007 I am ok with you, assembler is great.
I wrote my last project in C because a lot of use of floatting point instructions. I am poor using them.
But with asm (64 bits) I have created a window in 3 lines!
With all new instructions SSE, MMX,... that becomes hard to uderstand.


Now I like C as much as ASM.


I finish my project (a Sexy Text Editor) using RichEdit 5, after I rewrite in ASM.
Title: Re: Writing C code is fun and can be addictive
Post by: colepc on March 21, 2015, 02:00:44 pm
Back in the old days of DOS I had a text file of names of men who served in my old Vietnam unit that came from old orders, rosters, and other sources. Although most names were of men who were "lost" after returning from Vietnam, it also included names of those I found and the names of those who were known to have been killed in action.

During those old days of DOS, memory was expensive and limited. My list of names became so large it was about to exceed the file size limit. I therefore designed a C program to print a condensed version of the text file. Each name included information about the ex-soldier and a lot of that information was repeated over and over. I came up with a simple code scheme for those repeated phases I could embed in the text file and the C program would convert those codes back to the full text for printing. The C program could even select one or more years the soldiers served in case an ex-soldier was interest in a list of names of those he might remember. I no longer use that program because memory became cheap, the file sizes increased, and the newer generation of computers and printers meant I could no longer run my C program. Also that list of names is now on-line so I no longer get requests for my list. That C program was a really fun project.
Title: Re: Writing C code is fun and can be addictive
Post by: colepc on March 21, 2015, 04:36:36 pm
I have written in machine code, assembly, and basic. All of them allow spaghetti code. C is more structured and avoids those nasty jumps going all over the place. C was a tough nut for me to crack in the beginning and I probably will never be very proficient with it. I know enough to get by (at least for my simple projects). I don't know what linked lists or binary trees are so library creations will have to wait for quite awhile.

My first program language was Fortran using punched cards in the early 70's (I made many a card house with those cards). It was a course I took in college. We were assigned programming projects and the grade was given as to how many times the program was submitted (once for an A, twice for a B, etc). I made an A because I checked and rechecked all my programs. Unfortunately, now-a-days I'm not quite as thorough letting the compiler/linker tell me about most of my errors.  I always try to maximize warnings as they can also help find a lot of my errors. Having said that I checked the Pellas C warnings level I'm using. It was -W1. I changed it to -W2. I've a lot of work to do.

Title: Re: Writing C code is fun and can be addictive
Post by: Bitbeisser on March 22, 2015, 05:56:19 am
I have written in machine code, assembly, and basic. All of them allow spaghetti code. C is more structured and avoids those nasty jumps going all over the place. C was a tough nut for me to crack in the beginning and I probably will never be very proficient with it. I know enough to get by (at least for my simple projects). I don't know what linked lists or binary trees are so library creations will have to wait for quite awhile.
Well, Google is your friend...  ;)

The basics about those (linked lists, binary trees) are programming basics, independent from a programming language, just the implementation might depend on the language, some make it easier to work with those than others...
Quote
My first program language was Fortran using punched cards in the early 70's
Well, that would have been FORTRAN back then...  ;)
Quote
Unfortunately, now-a-days I'm not quite as thorough letting the compiler/linker tell me about most of my errors.  I always try to maximize warnings as they can also help find a lot of my errors. Having said that I checked the Pellas C warnings level I'm using. It was -W1. I changed it to -W2. I've a lot of work to do.
That is certainly a good way to go. Warnings are there for a reason, though it can be at time a bit hard to understand what exactly a warning is about. Lazy C programmers might go the other way reducing the warning level, so they don't get "bugged" that much. And then spending more time "debugging"...  ;D

Ralf
Title: Re: Writing C code is fun and can be addictive
Post by: Vortex on March 23, 2015, 08:09:01 pm
I have written in machine code, assembly, and basic. All of them allow spaghetti code.

Properly written code is not spaghetti. Today's assembly versions are providing high level constructs. ( Masm, Poasm, JWasm and SolAsm )
Title: Re: Writing C code is fun and can be addictive
Post by: Bitbeisser on March 24, 2015, 04:38:52 am
I have written in machine code, assembly, and basic. All of them allow spaghetti code.

Properly written code is not spaghetti. Today's assembly versions are providing high level constructs. ( Masm, Poasm, JWasm and SolAsm )
Not to mention that you can produce "spaghetti" code in pretty much any language. I am currently try to get my head around some libraries in both C++ and Object Pascal. And those would qualify from my POV most certainly as spaghetti code, being pretty much perfect examples of how not to use OOP...  ;)

Ralf
Title: Re: Writing C code is fun and can be addictive
Post by: henrin on May 19, 2015, 10:03:04 pm
As stated by colepc "What I learned about Win32 programs is that they are 40% fun and 60% frustration".
For me it is worst, partly because of the Win32 documation, so I managed to simplify Win32.

How:
- Not to add tons of interfaces.
- Not defining new basic types because they are already here.
- Not hiding the Win32 objects in case somebody wants to go inside.
- Just doing the ugly stuff which is necessary in each Win32 program and pushing it in a separate box.
- And leaving the application programmer do the fun: managing his own data, events, and doing basic graphics.

For this purpose, I an creating a Simple GUI Layer (SGL) (> 5000 lines) including :
- table (data grid)
- image the ones of GDI+
- separator
- panel
- graph
- panel
- text box
- popups
 and I plan to submit this work in the nexts weeks.

Attached is a simple example:
- application source code (470 lines) and resource
- the running 64-bit executable

PellesC is a great tool for doing such things.
Title: Re: Writing C code is fun and can be addictive
Post by: frankie on May 20, 2015, 12:01:02 pm
I an creating a Simple GUI Layer (SGL) (> 5000 lines) including :
- table (data grid)
- image the ones of GDI+
- separator
- panel
- graph
- panel
- text box
- popups
 and I plan to submit this work in the nexts weeks.
Nice job!  :)
Title: Re: Writing C code is fun and can be addictive
Post by: henrin on September 05, 2015, 04:40:50 pm
.. It took a bit more seconds to have SGL finished ..
(for version 1.0).

It is supposed to provide a simple layer on top of win32
for casual programmer and others.

Now it is released, see here :
http://forum.pellesc.de/index.php?topic=6788.0