newbie in programming

Thread Starter

King2

Joined Jul 17, 2022
79
I am a complete newbie in C programming. I am looking some advice from experts here.

I have installed code block in my computer. I have also started reading books for C language. I am still finding it very difficult to learn programming. I don't understand how to make learning programming easier.

Do you have any advice to make learning programming easier for newbie?
 

MrChips

Joined Oct 2, 2009
26,807
Welcome to AAC!

One way to learn programming is to write simple lines of code and get instant response.
What platform are you using, i.e. where is your compiler installed?
I would suggest that you use a compiler, i.e. code development platform that runs directly on your PC.
 

dl324

Joined Mar 30, 2015
14,924
Welcome to AAC!
I have installed code block in my computer.
What does this mean? You've copied some code to your computer or you installed a compiler? What operating system are you using?
I have also started reading books for C language. I am still finding it very difficult to learn programming. I don't understand how to make learning programming easier.
Most programming language books won't teach you how to program; they just teach you the language.
Do you have any advice to make learning programming easier for newbie?
Try creating flow charts (algorithms) to solve some problems that you're interested in. When you have one that covers all possible contingencies, you'll have something that can be coded in some language. It's possible to just start writing code and make things up as you go along, but that isn't sustainable for complex problems.

Start with some simple things like counting the number of times each word appears in some text; or something similar that interests you.

Study code that others have written and try to understand the algorithm being used. When you can understand what every line does and why the writer chose to do that, you'll have another program under your belt.

Be aware that "style" is a significant aspect of programming. Some write "flat" programs (no hierarchy, also referred to as spaghetti code for its messiness) and some have a main() that mainly calls functions where all of the work is done. Some like to split their code into many files and others will keep it in one or a few.

I've seen plenty of poorly written code, so keep that in mind if you're find something that just doesn't make any sense.

Program formatting can also make code easier, or more difficult, to read.

For example.
This code that creates a binary to BCD conversion table for the numbers 0-9999 intended to be programmed into a 16 bit wide EPROM such as MC27C4002 (from this thread). Each address converts the corresponding binary number to Binary Coded Decimal. It has no comments because it was intended to be single use and the algorithm was simple enough that I just made it up as I went.
Code:
main() {
  char *cptr, tmp[5];
  int i, fd;
  unsigned int bcdn;

  fd = open("bcd.dat", O_RDWR|O_CREAT);
  for (i = 0; i < 10000; i++) {
    sprintf(tmp, "%4.4d", i);
    for (bcdn = 0, cptr = tmp; *cptr;) {
      bcdn = (bcdn << 4) + *cptr++ - '0';
    }
    write(fd, &bcdn, 2);
  }
  close(fd);
  exit(0);
}
vs this, which is the same code minus the formatting that made it more readable:
main() {
char *cptr, tmp[5];
int i, fd;
unsigned int bcdn;

fd = open("bcd.dat", O_RDWR|O_CREAT);
for (i = 0; i < 10000; i++) {
sprintf(tmp, "%4.4d", i);
for (bcdn = 0, cptr = tmp; *cptr; ) {
bcdn = (bcdn << 4) + *cptr++ - '0';
}
write(fd, &bcdn, 2);
}
close(fd);
exit(0);
}
EDIT insert space in for statement to get rid of smiley face emoticon from ; ).
 
Last edited:

Thread Starter

King2

Joined Jul 17, 2022
79
I would suggest that you use a compiler, i.e. code development platform that runs directly on your PC.
I see that there are two ways to write program one of which has inbuilt compiler in which code can be tested by writing such as code block ide

Another way you are suggesting is to install the compiler directly on the computer and test it in command prompt by writing the code on notepad such as GCC compiler.

You have suggested second way, is there a specific reason for this? what would be the benefit of doing this?
 

Thread Starter

King2

Joined Jul 17, 2022
79
Try creating flow charts (algorithms) to solve some problems that you're interested in.
I have Windows 10 installed in my computer and code block ide to write and test c program

As per your suggestion i searched on internet then i came to know that the flow chart shows the flow of the program. I found the flowchart to be very beneficial for people who don't know programming, but it has a problem.
 

dl324

Joined Mar 30, 2015
14,924
Another way you are suggesting is to install the compiler directly on the computer and test it in command prompt by writing the code on notepad such as GCC compiler.
I'd suggest using an editor, like 'vim', that understands how to line up indentation and match parenthesis and curly braces.

There are some that color code things, but I'm old school and color coding isn't helpful to me because I won't take the time to learn what they mean. Vim seems to enable that by default and I always have to look up how to turn it off when I start using a new computer.
 

dl324

Joined Mar 30, 2015
14,924
I have Windows 10 installed in my computer and code block ide to write and test c program
On Win10, I use Debian running under WSL2 so I can use gcc.
I found the flowchart to be very beneficial for people who don't know programming, but it has a problem.
What is the problem?

A flowchart is useful for complicated programs that you can't complete in one session. It's also helpful if multiple people are working on the same program. I use Visio. I bought it before Microsoft bought the company and my copy from the 1980's is still sufficient.
 
Last edited:

Thread Starter

King2

Joined Jul 17, 2022
79
Yes i tried that compiler. I also wrote the code and executed it and saw the result.

I know what value the variable is stored in and where the value is stored. This can be seen with the print statement.

Would it be a good idea to create an excel sheet showing the name of the variable, the value of the variable, the address of the variable, and when the variable is changing its value?
 

MrChips

Joined Oct 2, 2009
26,807
Yes i tried that compiler. I also wrote the code and executed it and saw the result.

I know what value the variable is stored in and where the value is stored. This can be seen with the print statement.

Would it be a good idea to create an excel sheet showing the name of the variable, the value of the variable, the address of the variable, and when the variable is changing its value?
Why would you want to go to all that trouble when all the information is readily available with a print statement?
 

ApacheKid

Joined Jan 12, 2015
724
I am a complete newbie in C programming. I am looking some advice from experts here.

I have installed code block in my computer. I have also started reading books for C language. I am still finding it very difficult to learn programming. I don't understand how to make learning programming easier.

Do you have any advice to make learning programming easier for newbie?
Get a good book on C, of the many I read and relied on over the years this was by far the most helpful with the best written explanations.

1658415451157.png

I must have had ten books on C in the mid 90s, this one stood out and was helpful to me when structuring a large compiler project, forget the old "K & R" too, that's not a helpful book.

Why are you not using Visual Studio Code? or even Visual Studio Community Edition (both are 100% free of charge).
 

dl324

Joined Mar 30, 2015
14,924
I learned C using the first edition of K & R, in a one-week class by the manufacturer of a computer aided design workstation in 1983, and found it to be an excellent and concise description of the language. It was the book I kept in my office as a reference. The second edition was even better. The only other book I read for C was specifically for pointers.

EDIT: I learned how to program in high school using BASIC and had learned another half dozen languages before I learned C.
 
Last edited:

ApacheKid

Joined Jan 12, 2015
724
I learned C using the first edition of K & R, in a one-week class by the manufacturer of a computer aided design workstation in 1983, and found it to be an excellent and concise description of the language. It was the book I kept in my office as a reference. The second edition was even better. The only other book I read for C was specifically for pointers.

EDIT: I learned how to program in high school using BASIC and had learned another half dozen languages before I learned C.
The noteworthy thing about Hansen's book is that it discusses aspects of the language that are a bit obscured in K&R. For example it covers all of the different ways one can use structure tags and typedef or declare pointers to structures and typedefs, I found the coverage of this much more readable, the K&R book either skimmed over these things or presented them in an academic syntactic reference manner.

I never really found K&R much use, perhaps early on in the life of C it was, but by the time I was learning it in the mid 90s, there were quite a few more books.

I just wish I had written K&R, I imagine the royalties are still pouring in!
 

Thread Starter

King2

Joined Jul 17, 2022
79
Why would you want to go to all that trouble when all the information is readily available with a print statement?
The print statement tells me the value of the variable and the location of the variable where it is stored.

I write on a paper what is being stored with the location when the program is executed line by line from beginning to end. When the value of a variable changes in the program, in its location, I erase the old value with rubber and write the new value.

That way it's easy for me to understand what happens when a any single line is executed on the program
 

MrChips

Joined Oct 2, 2009
26,807
The print statement tells me the value of the variable and the location of the variable where it is stored.

I write on a paper what is being stored with the location when the program is executed line by line from beginning to end. When the value of a variable changes in the program, in its location, I erase the old value with rubber and write the new value.

That way it's easy for me to understand what happens when a any single line is executed on the program
That's good.
Once you become familiar with this and you develop confidence on how to write proper code you wouldn't have to do this again except for diagnostic purposes.
 

dl324

Joined Mar 30, 2015
14,924
I never really found K&R much use
The thinking of Kernighan and Ritchie was that C wasn't a big language and didn't need a big book to explain it. I agree with them. If you can't describe the language in a couple hundred pages, you're not trying hard enough.

Ritchie was such a giant in the field, I felt a personal loss when he died; even though I never had the pleasure of meeting him. I did, however, read a lot of Unix documentation he wrote. I had a printout of all of the Unix man pages and I read about every command when I was first learning to use Unix (actually Eunice and Ultrix before BSD and System V and AIX and HP-UX, then multiple flavors of Linux).
 

ApacheKid

Joined Jan 12, 2015
724
The thinking of Kernighan and Ritchie was that C wasn't a big language and didn't need a big book to explain it. I agree with them. If you can't describe the language in a couple hundred pages, you're not trying hard enough.

Ritchie was such a giant in the field, I felt a personal loss when he died; even though I never had the pleasure of meeting him. I did, however, read a lot of Unix documentation he wrote. I had a printout of all of the Unix man pages and I read about every command when I was first learning to use Unix (actually Eunice and Ultrix before BSD and System V and AIX and HP-UX, then multiple flavors of Linux).
I never developed a fascination with Unix myself. It was certainly prominent even back then but it always appeared sloppy, a glorified hack job. Of course there were few options for operating systems back in the 70s nd 80s so it was useful to have the choice.

There were (are) umpteen varieties of it too, this variant and that variant each with their own idiosyncratic bent, uniformity was never a big feature that I could see and the GUI was a bolt-on (well, there were several).

Unix grew out of the earlier (and much more impressive) Multics project (in fact the name Unix is a play on the name Multics). Multics was the first OS written in a high level language (PL/I) but was never commercially successful and was large too I guess.

Something I hated (to this day in fact) is the obsession with abbreviated names which Unix and C seemed to attach huge importance too, like it was a fashion and many systems I saw that used or ran on Unix followed that lead, cryptic shortnames everywhere.

Conisder: printf or sprintf or strcat for example, I am fine with abbreviations but they could have been optional, with a more meaningful name as the true name.

In Multics for example commands were very readable and a user had an optional abbreviations file that was used when they logged in, that way they could use (or define their own) abbreviations.

For example to copy a file in Multics: copy_file or to start a process runing: start_process, many people would use cf and sp for these but the documentation always used the full names and the full names were pretty much self explanatory.

Its odd how C and Unix caught on though, I think this was because many colleges and universities had such systems because there was little or no cost. Back then IBM, DEC etc likely charged a leasing fee for their OS and language compilers!

C was always burdensome in that it has a very limited number of data types, even strings are not first class types in the language which I thought was just too much minimalism. The C grammar has (IMHO) plagued languages ever since, to this day there are characteristics in Java and C# that exist only because of the prominence given to the C language grammar.
 

k1ng 1337

Joined Sep 11, 2020
651
Try learning Python. By far the most human friendly language I've tried. If you haven't already, try a Linux operating system as well. The way everything is set up is much different than Windows based systems and languages, more secure and user friendly. Python is largely integrated into Linux as are some other languages that you may come across like Java and Perl. The command line of Linux is essentially a language of its own.
 
Top