I've been learning C via C programming, a modern approach the second edition

I've been learning C via C programming, a modern approach the second edition.

I'm on page 244.

Why are arrays and functions fucking hard? The concept is not hard to grasp but when it advances, fucking hell. There is this one quicksort program that takes 10 numbers and sorts them. It is just so fucking hard to understand. I started just 5 days ago writing "Hello World" and now this shit.

Either this book is not suited for beginners or I'm a brainlet. Probably the latter. I just want to kill myself already.

Attached: c.png (225x225, 3K)

Other urls found in this thread:

github.com/PeterBadzhakov/Prolog
b-ok.cc/md5/8DA872E974D71A3DA307F439DC269560
twitter.com/SFWRedditVideos

It's fine to find it difficult at first. Don't worry. Once you understand the first concepts it'll be easy to learn how to program then. But if you struggle too much, then just give up.

Quicksort is a pretty advanced algorithm for a beginner.

I can't grasp it anons, wat do? Study arrays and functions more? From other sources?

He can't into debugging.
>Find another career path or do what you mommy does and stand on a street corner sucking black gentlemens cock for crack.

Who are you quoting?
What else do you have difficult with?

Just take it easy, experiment and fuck around with the code. Take a look at other people's code, and try to deduce what the code does, and alter some random shit in it. This is how I learnt the basics, and then moved forward.

Most books aren't that great for beginners.

>google c cheatsheet
>find an api reference
>start writing something

>Who are you quoting?
Quoting what ?

Visualize the memory when programming in C, a function is just a jmp to a certain memory address, an array is just a pointer

Sometimes recursive functions, I need to read it 2-3 times to understand it completely, but I couldn't grasp the quicksort program at all.

Thanks user. What would you suggest as another source?

We had to implement it in my 101 and I don't remember having any issues with it. The algorithm isn't a problem by itself, if you have the right learning aid. I haven't read OP's book but even if it was a good resource it could still be a bad resource for them in particular since everyone learns different.

reading code written by others is never easy, if you don't understand then just skip it and come back later

Go to leet code and solve some ez probs.

Try duck debugging.
Post your code and try explaining what it does right up to the point where you get confused or it's wrong. Then try to tell me why you think that is.

What post are you even quoting? That seems so random.

why dont u try and implement quicksort, might take you a day. but youll have a better understanding of it then.

I'll start over again user, just from the part on the book where array arguments in fucntions are explained. I'll try better.

Makes sense user. I'll go back and start again.

If you're a beginner in programming, don't do quicksort. Go back in 1 year when you're ready.

>might take you a day
Takes literally 1 min in haskell:
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a

Yeah, it takes one minute in a language that's literally only useful for trivial examples of algorithms, and is otherwise awful for any kind of program that would be interesting or compelling to any human being.


Gee, I wonder why he isn't going to be using Haskell.

Attached: b2f.png (795x991, 509K)

>why he isn't going to be using Haskell
You want a functional language to do algorithms, then a normal imperative language to do the normal things like UI or web services.
You could write the algos in F# then do the rest in C#.
Same in Scala/Java i guess.

Is F# the future?

I don't know, but it is interoperable with C#. Meaning you can call any .NET library from F#, and the C# part of your program can call into the F# part.

The haskell/C thing on the other hand could only be done using a process for each part and they would be two separate programs.

>Arrays and functions
You're a brainlet user. Try learning how to work a cash register instead.

Programming in C by Stephen Kochan is a good book, maybe you should try that

It's kinda lame and unwelcoming but the truth is that learning C/C++ requires you to learn a lot of the concepts first, dive deep into concepts and theory and then start with simple practice. It will not make your practical part easier, it will not make you solve the problems faster but by solving them you will learn a lot and will eventually understand it much better than going for it without all the necessary theory. Quicksort is also a pretty hard algorithm for a programming newcomer, the book seems to be aimed at people who already have some programming knowledge.

#include

static inline void swap(int *arr, size_t a, size_t b)
{
int tmp = arr[a];
arr[a] = arr[b];
arr[b] = tmp;
}

void quicksort(int *arr, size_t len)
{
if (len

Oops, looks like you're doing the opposite - learning programming via C programming.

Stop before it's too late, you'll develop detrimental habits like constantly imagining pointers and using procedural programming as a crutch.

I highly recommend you put C down for a moment and use Declarative or Functional languages for algorithms themselves, like Prolog or Lisp. They remove the syntax bloat and let you work with bare concepts.

For instance, quicksort is a divide-and-conquer algorithm. Divide, act, rebuild. A sequence of elements is sorted if each of its subsequences is sorted. Therefore, split the sequence into subsequences and sort them instead. The trivial sort is, given two adjacent elements a, b:
if a > b then swap a and b
else no_operation

Quicksort is unique in its fashion of split, you choose a pivot x (which may not even be a member of the sequence!) and create two subsequences L and R, such that:
L contains all elements of the current sequence

If you're following the exercises, make sure you're using a suitable standard.
I was writing python extensions in C, and I was trying to add a dynamically-sized array as the last member of a struct. Wouldn't compile, for it for an hour or two, then realized that is only a feature of C99, which is not supported by msbuild.

R contains all elements of the current sequence > x

If you're interested, here's my prolog code:
% partition(Pivot, List, LL, RL).
quick_sort([], []).
quick_sort([H|T], SL) :-
qs_partition(H, T, LL, RL),
quick_sort(LL, SLL),
quick_sort(RL, SRL),
append(SLL, [H|SRL], SL).
qs_partition(_, [], [], []).
qs_partition(Pivot, [H|T], [H|LL], RL) :-
H #< Pivot,
qs_partition(Pivot, T, LL, RL).
qs_partition(Pivot, [H|T], LL, [H|RL]) :-
H #>= Pivot,
qs_partition(Pivot, T, LL, RL).

More at github.com/PeterBadzhakov/Prolog

Read left to right, top to bottom.
X :- A, B, C .... is "Predicate (functor) X is True if predicate A is true and predicate B is true ..."

Therefore,
A sequence with first element H(ead) and all the rest T(ail) becomes sorted sequence SL (sorted list), if:
>by partitioning the T(ail) with the pivot H(ead), we receive LL (left list) and RL (right list)
and
>LL and RL are sorted into respectively SLL and SRL
and
>by getting SLL, adding the pivot H to it and the SRL, we receive the SL (sorted list) we long for

Very simple indeed. You simply repeat the algorithm but in mathematics. Cause and effect - say what happens to which elements, the program does the 'how'. Don't fiddle around with pointers and weird swap functions.

HTDP THEN PAPL THEN WHATEVER

For various reasons, I now have to code C on Win10. I used to use VimGUI on Arch and compiled from the terminal, what's a comparable lightweight program on Win10?

emacs (GUI), neovim. vscode (vscodium) uses less than 20MB RAM on my machine. It's a meme that electron apps are heavy.

thanks bud
by the way, are there Makefiles in Windows?

learn how the stack and heap work and memory will make a lot more sense to you
also learn some basic assembler

Sure there are, you just need the respective interpreter. Usually though, developers will straight give you a visual studio .sln file. I really do recommend also getting visual studio community for this reason, it's free of charge and limitless license.

find another book.
have multiple explanations/examples for the same shit so if one retards way makes no sense some other idiots will.

ah, alright, thanks!

How will any of that help understand abstract mathematics?
Have fun.

Haven't read the book but your issue may be with pointers
protip: pointers are fucking magic and let you do crazy shit. Learn to use them and your codebase will shrink tenfold.

C was my first programming language. learning it made way for me to easily tap into environments that adopted a language with an algol-like syntax, and in that regard I thank my lucky stars. But from a purely pedagogical point of view, it might have been unfortunate that C was my first language, because, you see, it is marketed as being a high level assembly language and modeling the computer's underlying architecture. This might have been the case 30 years ago, but today, it no longer stands true. In hindsight, given the choice, I would have gone with a seemingly simple computational model, one that lets me evaluate expressions and get back results as I type them in, and iteratively build on simple concepts more advanced and complex ones. So in my opinion a REPL is a must have. The concept of a pointer is extremely important, Having it being tied to manual memory management is unfortunate for newbies, since that requires them to focus on a technical detail that can be postponed to a much later stage of learning or be all together delegated to a computer architecture course. Given the right choice of starting course you might go from complete noob (I am assuming a good high school education here), to having covered software engineering from first principles, up-to and including areas that an active engineer can't afford to ignore, like program metrics, parsing, different computational models (the stuff making up VMs), etc...
SICP has all the merits cited above and then some, if it isn't about C for you but about the craft of making computer programs, then I would suggest rethinking your approach. Having said that, I am in no way belittling C, for it has its merits, not the least of which having tons of active huge code bases written in it, and libraries to match.

These. don't learn C as a first language

As someone who also learned from this book, and thinks it is a decent enough introduction to C and programming, my advice is to gloss over the quicksort section, and move onto the pointers and strings sections. Once you have done those, the earlier sections will start to make more sense as you get more comfortable with how C works in general. Basically, don't get bogged down on specific use cases of language features at the moment.

It's not until you get to the chapters about Structs and advanced pointers (the linked list data structure, memory management, pointers to functions), that you actually start learning about proper C stuff. You will feel like a brainlet a lot of the time, but eventually it will all make sense.

But having said all that, it was only when I moved to Python that I started actually writing useful programs for my work. I still haven't used C for anything other than learning CS topics.

>trying to understand quicksort while learning vectors and functions
when you start learning pointers, try to wrap you head around the fast inverse square root hack, why dontcha?

There is nothing that conceptually stops C or any other compiled language from having REPL or similar dynamic environment. If you play with dynamic linking and loading, you can even reload the program on runtime.
You can get a lot from using gdb that way. I'm surprised this didn't become a trend and the tools are in the not so usable state. Cniles are retarded and were decades behind from day 1.

college courses in this CS would take weeks to even get to functions, quicksort probably doesn't show up until the second semester. You're being too hard on yourself. Just don't give up and learn to relax and take a break if you don't get something.

Even java would be a better starting language.

Attached: doomguy-finally-realizes-why-he-can-amp-039-t-drink-his-coffee_fb_2475069.jpg (300x300, 25K)

I don't think that is as easy as you make it sound, especially for a newbie for whom compiler/linker/dynamic loading might as well be synonymous with magical incantations. I remember having such a hard time using gdb for the first time, before coming to learn of and use its -tui option and setting emacs to interface with it.
The point of my post was to encourage building correct abstractions from the get go so moving over to a new language (environment) is a matter of familiarizing oneself with its idioms. I don't think I gained anything from wasting my precious youth back in my uni days chasing down those missing semicolons and dealing with C's particulars quirks :)

>java
>language

Attached: youre_gay_anon.jpg (600x400, 44K)

"Le who are le quoting xddd I'm comedy genius"
Of course is a tripfag tranny

I won't give up, thanks user.

Are you reading online or did you bought this book?

I've read the first 1u chap. Didn't find the rest online. Do you mind to share the link?

There you go user.

b-ok.cc/md5/8DA872E974D71A3DA307F439DC269560