Articles Hierarchy

Articles Home » other » learn C ( on a Win 10 PC or Raspberry Pi )

learn C ( on a Win 10 PC or Raspberry Pi )

intro
use CODE::BLOCKS IDE
learn C basic tutorial
play Processing JAVA
C desktop app
Win32 GUI
C on Raspberry Pi
RPI 4


intro



today i was asked ( by my 14 year old nephew ) how to start learning the C language


- - my first reaction was to say that this might be the most difficult and demanding but powerful language to start learn coding

- - that i actually never even try it from a windows PC ( only from Raspberry Pi Linux RPI to learn GUI programming)


back to the very basics:
a program / code is a text file with english like commands and syntax
what can be translated via a compiler ( for that language syntax / operating system) to create a run-able program
( .exe for windows )
if you install that compiler program for windows you would still have to work on DOS level.

to close that gap to a desktop environment can use a IDE

+ + with a few seconds of google search i see one way could be to use
CODE::BLOCKS


alternative to code::blocks you might try to use ECLIPSE IDE
from eclipse get eclipse-inst-win64.exe (52MB).



use CODE::BLOCKS IDE


the first steps:
install code blocks on win 10 PC
( see also youtube )
codeblocks

download for windows
see here that the newest version is from 30 Dec 2017, might have been not the smartest IDE selection.

there click on the link to get the "mingw" setup ( comes with GNU C compiler )
codeblocks-17.12mingw-setup.exe via Sourceforge.net
and see
auto download with lots of confusing advertisements links..

now find and install codeblocks-17.12mingw-setup.exe (86MB) as admin.

here see the desktop with icon and first start window:



IDE help: here
C language help here


sadly that not comes with examples, so the way to your first program
would be little bit more as a click.
youtube
beginner
video tutorial


learn C basic tutorial


now try: learn C basic tutorial


play Processing JAVA


if you dig deeper into programming languages you read that JAVA and C are very different things,
( and i not want to compare them ) but if you read some basic code snippet it looks same.
here a idea, play Processing ( JAVA ) for a few days,
not need to try coding, just READ over and RUN the examples.
for check on single commands take a look at the reference.

until now in C we did actually only DOS programs, using JAVA, with the Processing library,
shows the thinking how to make ( graphic ) desktop apps easily.
from Processing download processing-3.5.4-windows64.zip ( current version for win 10 )
unzip like to a c:/users/me/Documents/
and find c:/users/me/Documents/processing-3.5.4/processing.exe ( start / make shortcut to desktop... )
at first start get created c:/users/me/Documents/Processing, your code / examples / tools ... directory
you could move from the MENU / file / preferences

use
MENU / file / examples // for a first test, press RUN
and windows defender will ask you to allow run JAVA

after you get a idea about creating a graphic window,
also using keyboard / mouse, draw shapes ( basic JAVA processing functions )
try the top addon library G4P:
goto
MENU / tools / add tool // libraries / G4P and install
MENU / tools / add tool // tools / G4P GUI Builder and install
now find the added examples under
MENU / file / examples // contributed libraries / G4P /...

last exercise of that short side step to Processing JAVA is, run the
MENU / tools / G4P GUI Builder
and make a button, save the created code and run it.


if you like Processing for its graphic capabilities, try ( JAVA or JS version )
with my TUTORIAL: from Button to Game!

as with JS it is very easy to make a ( interactive ) graphic data representation ONLINE
online editor and presentation



C desktop app


back to CODE::BLOCKS and language "C": now if we look at the provided templates

there are a lot what can be used for desktop apps ( creating a desktop program window under win or linux )
top might be QT what requires that that is installed additionally, we should try the open source / community / free version from QT.io


Win32 GUI


but we start what might be the entry level: win32 GUI project
with this you can understand the first steps of desktop program development, but serious projects might never be done with it??

anyhow we start with
+ new project
+ Win32 GUI
+ dialog based
+ BUILD & RUN
and get a DOS cmd window and a empty app window
what ( after only see DOS text output ) is a big step.



pls note that the main code file created has the ending .cpp so we not learn C here,
it is already C++



for next step i found at youtube more info:
when we look at the source of that "empty window" code we find a file resource.rc
what tells us we could use the tool from resedit.net


unzip and start, set include path


also i recommend to link resource.rc "open with"
from codeblocks to the ResEdit.exe so it appears like a integrated tool.

and open the same codeblocks project Win32GUI_dialog now with this tool


rename the main window caption, add a input window and a button

pls. note that the 2 elements show up in the main window without any additional coding,
i doubt you could just edit the .rc file manually: resource.rc

but yes, there need to be a next step where we get the button to work ? to do something ? on mouse pressed..
the 2 elements ( editcontrol and button ) have a ID, that we must set first here to 201 and 202
and detect mouse click on button and read and print caption content of editcontrol
main .cpp



C on Raspberry Pi


now we try the C language from Raspberry Pi ( Raspbian Linux )
info:
here work with
DEBIAN buster
Linux version 4.19.97-v7+
Raspberry Pi 3 Model B Rev 1.2
date: Mon 2020-03-16 15:26:22


-1- just from command line ( as compiler GCC is preinstalled )
info here and here

in some work directory from terminal:

nano hello-world.c
( paste code from original code ::blocks example )
gcc hello-world.c -o hello-world
chmod +x hello-world
./hello-world


Hello, World!

-2- or use ( pre-installed ) GEANY


-3- or install code_blocks under linux too.
sudo apt install codeblocks



-4- try QT5
( make sure have 2GB free )

sudo apt install qt5-default
optional:
sudo apt install libxext-doc default-libmysqlclient-dev firebird-dev libegl1-mesa-dev libgl1-mesa-dev libpq-dev libsqlite3-dev unixodbc-dev

sudo apt install qtcreator
optional:
sudo apt install qtbase5-examples qtbase5-doc-html



but if you follow above recommendation and also load the examples you see

and can load the example APPLICATION
what is the essence of a desktop program ( File Open / Save header menu )
you can use the help what has the quality of a tutorial / do project create / Build & Run /

note:
- - i can not switch ( from this QT Creator to the QT designer ( window designer / it is greyed out )
- - and the resulting running desktop app seems to have errors about the ICONs / buttons files??


RPI4


more