Learning 'C'.

@JasKinasis @captain-sensible
Just a little background on what I have been doing. I have a few books on Linux ranging from 'Cathedral and the Bazaar' to 'Introduction to the Command Line' to 'Assembly Language' and a few others.
What I have been practicing is 'C'. I guess that's why g++ and clang kind of threw me for a loop.
My purpose for learning 'C' was simply to get a little acquainted with what programming is and perhaps a little about how it works.
I have a book on 'C' that I have looked at {got it from Z-Library online}. It's called 'C Programming in Linux by David Haskins.
So far, I have learned much more than I thought I ever would - which isn't really very much.
However, onward we go!!! Charge on ahead is my motto!!!
Jas - Would you recommend that I practice 'C++' instead of 'C'? My understanding is that if I learn 'C' it is a small jump to learn 'C++'.
OG TC
 


some say if you learn C , you wil have to unlearn the bad habits and therefore jump straight in with c++
 
I know this may be a bit of topic but since we are talking about compiling and programming here I thought this may be interesting to share as well. Source code for Command Module and Lunar Module since it is written in something much older than C and C++.
 
@captain-sensible @wizardfromoz @Condobloke @LorenDB @f33dm3bits
Thanks to all you guys for your help.
I have settled on learning old fashioned 'C' for the present time. After looking at 'C++' and some others, it seems like 'C' is easier for me to grasp.
Again, thanks for all your input.
OG TC :cool:
When I have questions about 'C' I will pop them on you! {That's after Googling first. LOL}
 
some say if you learn C , you wil have to unlearn the bad habits and therefore jump straight in with c++

I wouldn’t say bad habits per se. It’s more a case of doing things differently.

When you come from C and you start learning C++, there are certain things that are done differently. It’s the same when you start learning any new programming language.

For example - when starting out with C++, one mistake that C programmers commonly make is to use familiar C code and C library functions in their C++ programs and then augment their code using classes and other functionality from the C++ std:: library. When in many cases - they would be better served simply using C++ for the entire project.

So although both languages are closely related AND any valid C code will work in a C++ program, it is worth remembering that they are two separate, distinct languages.

Different programming languages often solve problems in slightly different ways and require a slightly different mindset, or way of thinking. So part of the problem is learning new syntax. Another part is learning the mindset!

I have settled on learning old fashioned 'C' for the present time. After looking at 'C++' and some others, it seems like 'C' is easier for me to grasp.

Awesome Charlie!
C is a great programming language to learn.

Personally, I learnt C before learning C++. And learning those two languages was a game changer for me. Between them, I learnt enough transferable skills to be able to learn ANY other programming language.

And since becoming a professional programmer - I have ended up learning and using a LOT of additional programming languages. Some were out of my own curiousity, but many were from an immediate professional need, during work projects.
 
Last edited:
I wouldn’t say bad habits per se

yes thats true . my understanding is that Bjarne Stroustrup took C and enabled OOP to become c++ so that there were classes and class members; but that it evolved so much the two have diverged quite some. I'm half decent with OPP php and as you say once you have gone over concepts lets say template classes and instantiation to objects, the syntax may be a bit different but there is a similarity that makes it easier to take it in of a 2nd language after you have done a bit with a first language.
 
@JasKinasis
Help!!!
As you can see, I have not progressed very far ---yet.
I have a problem that I can't figure out. I'm quite sure there is a simple answer but it has me bumfoozled.
Here's a screenie of the prog and my attempt to compile it.

Screenshot from 2021-02-02 20-55-37.png


I know it is telling me what the problem is, but I don't understand it.
Thanks for your help.
Old Geez TC
 
@JasKinasis
Help!!!
As you can see, I have not progressed very far ---yet.
I have a problem that I can't figure out. I'm quite sure there is a simple answer but it has me bumfoozled.
Here's a screenie of the prog and my attempt to compile it.

View attachment 8406

I know it is telling me what the problem is, but I don't understand it.
Thanks for your help.
Old Geez TC
I would think you might not have the development package with that header file installed, not sure which one you need but you might need this one: libc6-dev: /usr/include/stdio.h (Not sure which distribution you are running)
 
Linux Mint

(exits):)
 
Linux Mint

(exits):)
That package exists under Mint as well but there are quire a few other packages that have that same file, just do the following.
Code:
sudo apt install apt-file
sudo apt-file update
apt-file search stdio.h
Then find the one you need and install it.
 
Last edited:
As @f33dm3bits has pointed out, you probably don't have libc-dev installed, which you'll need in order to compile and link C code..

On Debian the current package is libc6-dev. But if you're on mint, they might be using a newer version. IDK.

Maybe try searching:
Bash:
apt search libc[0-9]-dev | head
There are a lot of different versions of libc-dev, for cross compiling to different processor architectures. The query above will search for packages that match libc?-dev, where ? is a number between 0 and 9.
Piping the result to head should show the first few packages that match that pattern. The one you'll want should be the very first one.

If apt does not say [installed,automatic] next to it, you'll need to install it.

If it already says [installed,automatic] I'm not sure what to suggest.....

In that case, perhaps try installing, or reinstalling the build-essential meta-package. That should install all of the dependencies you'll need for building software.
 
@JasKinasis @f33dm3bits
Thanks guys.
That's kind of what I thought might be the problem, but did not know what to do about it.
I shall return with the results, soon.
OG
 
@JasKinasis @f33dm3bits
Thanks guys.
That's kind of what I thought might be the problem, but did not know what to do about it.
I shall return with the results, soon.
OG
@JasKinasis @f33dm3bits
Thanks guys.
I followed all the suggestions of you both.
It is a success!!! as per the screenie.
now.png


Evidently not a total success just yet. The compiling problem is solved but how do I take care of syntax error? I don't see any error in the prog. Am I missing something? Maybe something I'm doing wrong?
OG
 
As @LorenDB has pointed out - don't run the .c file.
You need to run the executable created by gcc.

It's not the same as running a shell-script, or a python script, where the commands in the script are interpreted and executed.

With C you use a compiler like gcc to compile the source code and then link it with any required libraries, in order to produce a native executable that you can run on your system.

And you won't need to change the permissions of the executable, it will be created with executable permissions by the compiler/linker.

With gcc, if you don't specify a name for the executable using the -o option, it will create a file called "a.out", by default.

So as things stand - after running your .c file through gcc, simply run ./a.out to run your executable.

To give the executable a name, try compiling it like this:
Bash:
gcc now.c -o now

That will compile your code and create an executable called "now". Which you can run like this:
./now

I hope this helps!
 
Last edited:
@JasKinasis @f33dm3bits @LorenDB

A hearty thanks guys from the Old Geezer.
Everything is now working fine. We can now call this - Case Closed! (and now this OG can get a good nights' rest, until the next problem arises. LOL.)
Old Geez TC
I hereby propose this toast to you all you guys:

Here's to it and from it and to it again,
If you ever get to it and don't do it,
May you never get to it to do it again!!! Now repeat it real fast.

It took me a month to remember that because we had had a few beers before our old buddy repeated it at the bowling alley.
 

Staff online

Members online


Top