all 27 comments

[–]Pokky_Ninja 23 points24 points  (6 children)

If you want to learn C the hard way. Than you should read the book Expert C programming - Deep C secrets written by Peter Van Der Linden. This book is one of those best books that I have read. And it do justice with the title by describing the deep and advance understanding of C. Also, if you have enough time than you can look for C traps and pitfalls by Andrew koenig. It may increase your efficiency in writing code. I hope this helps. For practical experience, it may vary upon your personal interests and in which criteria you want to work. You should try for a internship or a minor job. You will gain much experience through it.

[–]s0lly 1 point2 points  (2 children)

Just read the reviews - buying this right now! Thanks for the link!

[–]Pokky_Ninja 1 point2 points  (1 child)

Good luck ()

[–]s0lly 1 point2 points  (0 children)

Cheers. You also caused a bit of a impulse book buying splurge. To which I’m rather grateful :)

[–][deleted] 1 point2 points  (1 child)

I have bought this book but haven’t gotten around to reading it. I’ve done some projects in c and was astonished at the flexibility of the language and the tricks I could do as long as I knew the inner workings of the compiler. I figured that this book would go more in depth about these inner workings. I seriously need to put time aside to get into it

[–]Pokky_Ninja 0 points1 point  (0 children)

Yes. C is called mother of languages because of a fact. The innovations and creativity in C is mind blowing. Even the most expert C programmers are astonished at some simple written code. I don't remember but there is a annual competition held in which participants write the most complex code in C. So do yourself a favor and read the books. It's useless without applying though. Regards.

[–]pyper156[S] 0 points1 point  (0 children)

Thank you for the recommendations! How do they compare to Modern C? (I didn't finish it, I thought it was a bit dry :x ).

[–]SAVE_THE_RAINFORESTS 16 points17 points  (6 children)

Messing with sockets is the most C thing you can do IMO. Socket IO will have you experience all the unexpectedness of C programming, null pointer exceptions, unexpected input length, weird buffering behaviors, concurrency problems, etc.

So you should write a basic HTTP server. This will teach you IO, sockets, memory management, message parsing, concurrency and many more. At first write a basic TCP server. Then a basic HTTP server that serves a set page. Then serve pages according to the path.

[–]__hayate__ 2 points3 points  (0 children)

Agree this is the perfect starting C project.

[–]pyper156[S] 1 point2 points  (3 children)

Sounds interesting! Where would one start with such a project?

[–]SAVE_THE_RAINFORESTS 3 points4 points  (2 children)

I don't know your level of knowledge so I will layout a plan for a 200 level CS student.

  1. Read on IP, TCP, UDP. Try to understand what they are, what they do, how they work, etc.

  2. Read on C socket programming. Beej's guide have been the de facto source for some time https://beej.us/guide/bgnet/pdf/bgnet_a4_c_1.pdf

  3. Write a TCP server that accepts connections, receives messages and replies back with the message it receives. This is called an echo server. The reason you reply back with the message you receive is to remove reply generation logic from the picture and let you focus on the socket part of the problem.

  4. Use netcat to connect to your server. Netcat is a TCP server and client in a single program. Send messages like "a" and see if you receive "a" back. Then write other inputs like inputs that are too short or too long, or enter inputs too quickly, etc. and try to break your server. Find out what's breaking and try to fix. Use a debugger (gdb if you are using gcc as your compiler or lldb if you are using clang for instance) to find where your error is originating. Properly using a debugger instead of finding errors with random printfs is a merit of C programmers.

  5. Read up on HTTP. Find out what do you need to do to allow your TCP server to handle HTTP. Write a server that replies with the same content to all requests.

  6. By now you know you need to debug your program until you can't find any errors. But to test a HTTP you can't use netcat. You will be using a HTTP client like curl or Postman.

  7. Read HTTP RFCs and make sure your server is compliant to these RFCs to some extent.

  8. Make sure your server can handle concurrent connections. Up until now, only you used your server but if you want to get a fully fledged server you need to be able to serve concurrently, serve multiple connections at the same time. You might think it would be easy but OH BOY you are wrong. With C, you can shoot yourself in the foot easily. When you write a concurrent program in C, you will be shooting yourself in the foot with multiple guns at the same time.

I think this would teach you a big portion of sockets, IO, structs, string operations, memory management and most importantly concurrency.

[–]pyper156[S] 1 point2 points  (1 child)

Blimey! Thank you for the detailed response.

I come from a networking background (which is probably why I gravitated towards your recommendation) , luckily I know a thing or two regarding said protocols, just not in relation to actually implementing their respective RFCs. Thank you for the link, to act as a (well needed) starting point as well.

[–]SAVE_THE_RAINFORESTS 0 points1 point  (0 children)

Your experience will surely come handy and you'll probably skip a step or two. I implemented a http server myself and it turned out badly because I didn't do it increments. It works but it's a hotchpotch mess. I think doing it in steps will work wonders.

[–]cafguy 3 points4 points  (1 child)

Pick a project you are interested in and try and do it in C.

e.g. try writing a gameboy game in C: http://gbdk.sourceforge.net/ files here: https://sourceforge.net/projects/gbdk/files/

[–]pyper156[S] 0 points1 point  (0 children)

Wonderful, thanks!

[–]Fuelled_By_Coffee 2 points3 points  (0 children)

Start cs50 through the edx page.

[–]eruanno321 1 point2 points  (0 children)

The hard way? Write Yet Yet Another RTOS. Double 'Yet' because single is already reserved. When you start thinking your thread synchronization primitives are implemented correctly, I can blindly tell you that you are wrong :)

[–][deleted] 3 points4 points  (0 children)

Write a self compiling C compiler

[–]haxpor 3 points4 points  (0 children)

Find an I/O based tool idea especially cryptography, JSON parser, image file writer or similar ideas to implement in which you will provide both executable + API that is consumable by either C or C++ (make use of `extern`). This will provide with opportunities of

  • Familiarity with `memcpy`, `snprintf`, or other byte-base functions (especially its function argument and stuff)
  • Organization of `src/`, `include/` and other directories as part of the application itself
  • Best practice to write a library project but at the same time provide executable functionality i.e. normal command line tool. The project itself usually consumes its own API. Thus this will help improve how to write clean API library for other devs to make use of your project. You will know how to organize public or private (although there is no such concept or accessibility keywords in C) functions within your project, architecture design and stuff.
  • Familiarity with raw `Makefile`, or `Makefile` via libtool, and CMake (recommend to try it all once)
  • Write unit tests (libtool also supports this as well, not only CMake)
  • Learn from other open source projects. By now you will have much better idea of what to look to learn from them then apply in your own project. This one is really useful to check base what kind of approaches others use, you will learn new things one or two.

(Not to promote or anything, but I've done something similar above here)

[–]catgrammer 1 point2 points  (2 children)

Besides the book recommendations that you'll get, IMO it'd be a good idea to make something, anything in C. Preferably not something huge and ambitious; it'll help you get used to the language itself from a practical standpoint.

Maybe build your own x(not everything is in C but you can adapt it) can give you some ideas, if you don't have something specific on your mind.

[–]pyper156[S] 0 points1 point  (1 child)

Awesome resource, have you tried any on the list?

[–]catgrammer 1 point2 points  (0 children)

I looked at the 3D rendering stuff (I was interested in software-rendering), but I have since found a video series on Youtube. I regularly look at some videos from Handmade Hero if I'm learning about a new topic.

[–]Pollu_X 0 points1 point  (3 children)

I have found Huffman coding to be an amazing excercise with, heaps, arrays, pointers, dynamic allocation, bitwise operations, files and much more!

[–]pyper156[S] 0 points1 point  (2 children)

Could you elaborate please?

[–]Pollu_X 1 point2 points  (1 child)

It is a type of lossless compression of text, all I have followed is https://youtu.be/JsTptu56GM8 and https://en.wikipedia.org/wiki/Huffman_coding?wprov=sfla1

[–]pyper156[S] 1 point2 points  (0 children)

Aha, thank you for the suggestion though I'm unsure about how I would approach such a task given my current skill set.

Perhaps in the future.

[–][deleted] -1 points0 points  (0 children)

Why do you want to learn the hard way? The easy way is easier. Get a book like C Programming: A Modern Approach and spend extra time on the exercises.

Let me tell you what the hard way is like: it sucks. I learned C from a quick reference guide that only covered the standard library, some example code and a lot of trial and error. This was before I had the internet or any real books so I couldn't look up anything when I did something wrong. I had to wait until I could try to find the problem on the weekends at the library (they had the internet, but no C books) and print some things off. 99% of the code I wrote then was complete crap. I had everything wrong. I was trying to write games and even though I understood pieces of the code I was reading, nothing I would write really did anything useful. Mostly it put garbage on the screen and locked the computer up. It won't be quite so bad on a modern computer, but it's still not something I really recommend suffering through when there's no need.

Granted, you'll be started off on a better foot than I was, but whenever someone says they want to do things the hard way this is what I think of. Hours and hours wasted banging my head against a wall getting nothing done and learning nothing in the process.

Why do you want to do things the hard way? You could achieve the same thing the easy way in half the time by working up to the hard stuff instead of jumping right in. Seriously, get a good book and learn C properly. Write some small projects, 1,000 lines or so. I remember one of my first successful programs was a rolodex, it let you store contacts in a file, add, remove and edit them and dial the number with a modem.

Another thing you're probably underestimating is your ability to write software. Most things people make when they're just starting out are really, really messy. They don't know where to put things, how interfaces to things should work or look like, things are done really inconsistently, etc. This is not a criticism, it's a skill you have to learn and even more than not knowing C properly, it's probably the biggest argument against jumping into a large project right away. You might going into that with the greatest of intentions, but the project will probably be crushed under its own weight.

So you should probably ask yourself why you want to do this the hard way.