Learning 'C'.

OP
70 Tango Charlie

70 Tango Charlie

Well-Known Member
Joined
Oct 7, 2019
Messages
523
Reaction score
675
Credits
2,064
@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
 


captain-sensible

Well-Known Member
Joined
Jun 14, 2019
Messages
2,539
Reaction score
1,677
Credits
15,157
some say if you learn C , you wil have to unlearn the bad habits and therefore jump straight in with c++
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
3,893
Reaction score
2,631
Credits
28,122
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++.
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
6,620
Reaction score
5,378
Credits
19,579
OP
70 Tango Charlie

70 Tango Charlie

Well-Known Member
Joined
Oct 7, 2019
Messages
523
Reaction score
675
Credits
2,064
@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}
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,318
Reaction score
1,870
Credits
8,314
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:

captain-sensible

Well-Known Member
Joined
Jun 14, 2019
Messages
2,539
Reaction score
1,677
Credits
15,157
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.
 
OP
70 Tango Charlie

70 Tango Charlie

Well-Known Member
Joined
Oct 7, 2019
Messages
523
Reaction score
675
Credits
2,064
@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
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
3,893
Reaction score
2,631
Credits
28,122
@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)
 

wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
6,620
Reaction score
5,378
Credits
19,579
Linux Mint

(exits):)
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
3,893
Reaction score
2,631
Credits
28,122
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:

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,318
Reaction score
1,870
Credits
8,314
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.
 
OP
70 Tango Charlie

70 Tango Charlie

Well-Known Member
Joined
Oct 7, 2019
Messages
523
Reaction score
675
Credits
2,064
@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
 
OP
70 Tango Charlie

70 Tango Charlie

Well-Known Member
Joined
Oct 7, 2019
Messages
523
Reaction score
675
Credits
2,064
@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
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,318
Reaction score
1,870
Credits
8,314
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:
OP
70 Tango Charlie

70 Tango Charlie

Well-Known Member
Joined
Oct 7, 2019
Messages
523
Reaction score
675
Credits
2,064
@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.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top