News for hackers. Stuff that matters.
Re:Ask HN: What project did you tackle to learn C? by dahart on Saturday February 10, 2018 @11:51AM (#16348092)
@zabana what goals do you have in addition to learning C?

As you can see, the answers are all over the map. Nothing wrong with the question, nothing wrong with a discussion, but "write a program of some kind" might not help you at all.

It's worth asking why learn C, because the answer depends on what you want to do. I like C over C++ for various reasons, but I would still recommend C++ unless you have a reason. I like C++ but I would still recommend starting with Python or JavaScript unless you have a reason. C & C++ are for high performance. Do you need high performance for sure? C is harder to learn, use, and practice well, and slower to develop in than today's scripting languages.

Re:Ask HN: What project did you tackle to learn C? by mikerg87 on Saturday February 10, 2018 @10:38PM (#16351044)
I did every problem in the K&R C book and wrote a small program like a unit test demonstrating every function in the standard lib. The biggest gain I got was learning how to use Make to compile and run my suite of examples.
Re:Ask HN: What project did you tackle to learn C? by Stwerner on Saturday February 10, 2018 @11:11AM (#16347876)
I had a class in high school that mostly covered the basics, though I wouldn't say I "learned" it. It wasn't until around 15+ years later and after I started working as a programmer and decided to work through a Programming A Chess Engine In C [1] youtube series that it finally really clicked.

[1]https://www.youtube.com/watch?v=bGAfaepBco4&list=PLZ1QII7yud...

Re:Ask HN: What project did you tackle to learn C? by Hnrobert42 on Saturday February 10, 2018 @11:21AM (#16347922)
A webserver. Not fully compliant, but enough to show you how much you can accomplish in a small amount of code. Then a proxy server with compression. Used prhreads. Helped learning about race conditions, threading, mutexes, semaphors, etc.
Re:Ask HN: What project did you tackle to learn C? by TeMPOraL on Saturday February 10, 2018 @12:05PM (#16348166)
A complete tangent: I wondered if "prhreads" is a typo of "pthreads", or an actual thing. A quick Google query led me to discover that in Google Books' version of "Applied C++: Practical Techniques for Building Better Software", OCR must have confused 't' with 'r' :).

https://books.google.pl/books?id=xzbRQXXsy6UC&pg=PA130&lpg=P...

Re:Ask HN: What project did you tackle to learn C? by Hnrobert42 on Sunday February 11, 2018 @10:26AM (#16353028)
Sorry. Typo.
Re:Ask HN: What project did you tackle to learn C? by malkia on Saturday February 10, 2018 @01:04PM (#16348555)
I've learned C (after knowing Turbo (Borland) Pascal, and Apple Basic) by simply getting a book, and reading it for a year (I must've been in 10th or 11th grade, and that was way before any internet, and I had no access (or idea) of BBS). It was a bulgarian version (I don't think it was translation), and I remember being it a very solid and good book - I was able to use printf/scanf right after I've read the book.

Btw, I've switched to "C" for a stupid reason. I was writing a File Manager for DOS in Turbo Pascal (like Norton Commander, but single pane), and I got stuck how to move a file from one directory to another. The builtin Pascal function only renamed a file, couldn't move. I was told that "C" can do anything, so I started deep into it. To be honest, while the book taught me things, at first I was putting everything in .h files, as I was so much used to the much superior (even today) Unit system in Turbo/Borland Pascal.

Then some months after, getting Ralph Brown's interrupt List, and finding that I can just call a specific interrupt in assembly to rename a file (and that's what the "C" library had implemented), Pascal was no longer limitation...

But haven't touched Pascal since 1999, and moved to C/C++ since then. I still miss the Units (.TPU files).

Re:Ask HN: What project did you tackle to learn C? by danieldk on Saturday February 10, 2018 @01:26PM (#16348684)
Then some months after, getting Ralph Brown's interrupt List, and finding that I can just call a specific interrupt in assembly to rename a file (and that's what the "C" library had implemented), Pascal was no longer limitation...

I really loved SWAG, which was basically a collection of 'how do I?'-questions with answers in the form of Pascal sample code. Interestingly enough, it seems that someone converted it into a website:

http://swag.delphidabbler.com

As a kid I went through and studied many of the SWAG snippets.

But haven't touched Pascal since 1999, and moved to C/C++ since then. I still miss the Units (.TPU files).

Also, the compile times and the debugger were awesome. The Turbo Pascal IDE was still better than many current environments. I stopped using Turbo Pascal when I switched to Linux more or less full-time (near the end of the nineties), though I did use FreePascal on Linux a bit.

Re:Ask HN: What project did you tackle to learn C? by cf on Saturday February 10, 2018 @11:10AM (#16347867)
I re-implemented lots of basic unix tools. What I would do is go for a command, and just look through OS api references seeing if I could implement it. Once I got basic functionality, I would go look into the source code and check I did against the standard. I found it super-helpful.
Re:Ask HN: What project did you tackle to learn C? by jacquesm on Saturday February 10, 2018 @09:17AM (#16347349)
My first big C program was a full screen editor. I wrote it for the Atari ST using the (excellent!) Mark William C compiler. It still works today 3 decades later on Linux.
Re:Ask HN: What project did you tackle to learn C? by karimf on Saturday February 10, 2018 @10:16AM (#16347619)
I join the robotics club at my college. My team competes in national dancing robot competition. I help write the software to control the movements of 25 servos in humanoid robot using microcontroller (Teensy).

Coming from webdev and python background, i learn many things from it. Data types, pointer, byte shifting, serial communication. The most exhilarating part is when you have to optimize your code in every corner to fit in the small memory of the microcontroller.

Re:Ask HN: What project did you tackle to learn C? by drdebug on Saturday February 10, 2018 @01:02PM (#16348543)
I would recommend 2D graphics with a framebuffer. Drawing sprites, scrolling, drawing lines. You get to play with loops, pointers etc... Plain C, no extra library besides initializing a window and copying the buffer into a displayed window (SDL for example), a few calls. You could also save to a simple graphic format. Learning the standard library would come next, you could save to a file etc...
Re:Ask HN: What project did you tackle to learn C? by viperscape on Saturday February 10, 2018 @03:03PM (#16349276)
I second this. Write a basic game with 2d graphics, use SDL, and save and load the state to file. To take it a step further and write a networked version with your own basic byte encoding if each move and game state to keep in sync. This would teach you a ton of various topics.
Re:Ask HN: What project did you tackle to learn C? by berbec on Saturday February 10, 2018 @11:36AM (#16348009)
I read a fantasy/computer crossover series (Wizard's Bane) as a teen and remember a mention of the IOCCC. it fascinated me and I decided to enter. I spent most this and made a Mandelbrot fractal generator. I didn't win or get any recognition, but I still remember the code fondly. The source was in the shape of the fractal, used recursion, and was very ugly with ?:s everywhere, strange pointers and other ugliness. It could zoom and scroll. I was very proud of myself and always have kept C around. It's still my go to for little projects.
Re:Ask HN: What project did you tackle to learn C? by markbnj on Saturday February 10, 2018 @01:42PM (#16348772)
I think my very first C program was a vga graphics demo. I used Borland Turbo C, and this was probably 1989 or so. I was transitioning from a mix of Turbo Pascal and 80x86 assembler, and had fallen in love with Borland's whole toolset from the IDE to Turbo Debugger, which was a revelation for me. And I'll note that this was back when the only way to get a copy of these tools was to go to Egghead or another software retailer and drop $100+.
Re:Ask HN: What project did you tackle to learn C? by pjc50 on Saturday February 10, 2018 @12:43PM (#16348434)
Games. But this was back in the DOS era, when you could just treat the screen as an array and write directly into it, and many of today's languages weren't available.

I would suggest looking at the classic "Programming in the UNIX environment", which is dated in detail but very good on the UNIX/C design philosophy.

But as others have said, you need a specific reason to learn C now, rather than more modern languages.

Re:Ask HN: What project did you tackle to learn C? by mettamage on Saturday February 10, 2018 @11:43AM (#16348037)
I had a course on computer and network security at the Vrije Universiteit Amsterdam. One of its prerequisites is that you need to know C. I didn't know any. I told myself: I am language agnostic, I can learn a programming language on the fly.

The first assignment we had to do was bruteforce passwords on a Linux machine. There was a user text file and an encrypted password textfile. This was supposed to be easy, I barely passed it.

The second assignment was to simulate an attack that Kevin Mitnick did on a supercomputer. We had to spoof TCP sequence numbers from a computer that we didn't control, but back in the day TCP sequence numbers were guessable and in this assignment they made the guessability a bit easier. I think I used libraries such as libpcap and maybe anhoter one. I did a bit better than just barely passing.

Assignment three was looking at binaries with source code in C and find the vulnerability and exploit it. I nailed it.

That's how I 'learned' -- got some inkling of workable knowledge -- on C.

I'm a bit more mild on how easy it is to be language agnostic from the get go though.

Re:Ask HN: What project did you tackle to learn C? by gespadas on Saturday February 10, 2018 @11:16AM (#16347898)
A mimic OS GUI (a couple of windows, buttons, wallpaper changer, etc). It was really fun to code it... over 2 decades ago.
Re:Ask HN: What project did you tackle to learn C? by jehna1 on Saturday February 10, 2018 @01:12PM (#16348589)
Wanted to try to create a NES game on a game jam, so I started to create a bootstrap project for creating a NES game in C: https://github.com/jehna/nes-bootstrap
Re:Ask HN: What project did you tackle to learn C? by codingdave on Saturday February 10, 2018 @11:21AM (#16347924)
A simple database. Not useful, just as a learning exercise while in school many years ago, but it was written completely from scratch, even down to the physical read/writes from the disk.

I don't recommend doing that in a real app. But it was a good way to learn.

Re:Ask HN: What project did you tackle to learn C? by __s on Saturday February 10, 2018 @11:57AM (#16348123)
Brute force solutions were becoming too slow for https://projecteuler.net in Python, but with C I could put off being clever about the math
Re:Ask HN: What project did you tackle to learn C? by krylon on Saturday February 10, 2018 @11:31AM (#16347986)
When I first learned C, I wrote a program to check the Goldbach conjecture (every even number >= 4 can be shown to be the sum of two prime numbers). For a while this was the first nontrivial program I would write in any programming language I learned, but in retrospect it was pretty pointless on several levels.

It is a good project though, to learn about high performance arithmetic, data structures and has good potential for parallel implementations (I eventually rewrote it on top of PVM to run on a cluster of computers).

Re:Ask HN: What project did you tackle to learn C? by bradknowles on Saturday February 10, 2018 @09:10PM (#16350781)
My Numerical Methods class in college, in the mid-80s.

C was not an “approved language”, but I was told that if the grad student who was actually grading all the papers agreed, then I could use it. I went to talk to him, and turned out that he also wanted to learn C. So, he approved my request.

Because I was happy learning a new language, I made sure all my programs executed correctly, were written in what was then the correct style, and I still managed to turn in my homework before anyone else, for every single assignment.

Motivation matters.

Re:Ask HN: What project did you tackle to learn C? by shiado on Saturday February 10, 2018 @11:30AM (#16347976)
I would advise that you do something that requires networking, a database (probably SQLite), maybe some ncurses graphics. A minimal cli Bittorrent client is a great idea.
Re:Ask HN: What project did you tackle to learn C? by peterburkimsher on Saturday February 10, 2018 @11:50AM (#16348084)
A summer internship, writing a USB driver for a CPAP device. Parsing XML strings in pure ANSI C without any external libraries was a challenge, but I learned a lot.
Re:Ask HN: What project did you tackle to learn C? by ateesdalejr on Thursday February 15, 2018 @12:45AM (#16382195)
Sounds like a vulnerability waiting to happen.
Re:Ask HN: What project did you tackle to learn C? by theparanoid on Saturday February 10, 2018 @11:50AM (#16348086)
Guess I'm getting old. C used to be the language for game development.

I learned it from the book "Programming Linux Games" by Loki Software (remember them?).

Re:Ask HN: What project did you tackle to learn C? by aiansiti on Saturday February 10, 2018 @11:29AM (#16347966)
A followed the crafting interpreters series but reimplemented the python in c. Really gave me an appreciation for high level languages...
Re:Ask HN: What project did you tackle to learn C? by marmaduke on Saturday February 10, 2018 @01:20PM (#16348638)
I wrote a toolkit for stochastic differential equations, but I got bogged down trying to emulate virtual methods and inheritance, badly.
Re:Ask HN: What project did you tackle to learn C? by ktpsns on Saturday February 10, 2018 @12:18PM (#16348267)
My first C project was on a microcontroller (ATMega architecture/AVR-GCC) 12 years ago. I think a lot of people get in contact with C with Arduino these days.

My first real C project on x86 was a graphical user interface with Gtk+. However, I soon switched to C++ using Gtkmm, then using Qt.

Re:Ask HN: What project did you tackle to learn C? by jschwartzi on Saturday February 10, 2018 @11:38AM (#16348014)
I modified an embedded application for my then-employer's customer while I was working in product support. It made them really happy, and probably solved other customer issues as well.
Re:Ask HN: What project did you tackle to learn C? by mattmoss on Saturday February 10, 2018 @01:37PM (#16348744)
I learned C over 1990 Christmas break from university. At home, I programmed my father's Mac Plus and wrote a game similar to Light's Out but on a playfield not a square grid.
Re:Ask HN: What project did you tackle to learn C? by sidlls on Saturday February 10, 2018 @12:40PM (#16348405)
Scientific instrument device drivers and software with network and data reduction libraries to coordinate their activities and data collection in different locations on the planet.
Re:Ask HN: What project did you tackle to learn C? by snissn on Saturday February 10, 2018 @12:19PM (#16348276)
First went through the K&R text book then made small nginx modules and python extensions as well as random little Unix tools to replace built in tools that were slow
Re:Ask HN: What project did you tackle to learn C? by DamonHD on Saturday February 10, 2018 @09:22AM (#16347374)
A robotics operating system for the Z80 ~32 years ago!
Re:Ask HN: What project did you tackle to learn C? by sleavey on Saturday February 10, 2018 @11:51AM (#16348095)
A microcontroller with temperature, humidity, pressure, dust and light sensors, and an ethernet web interface. I learned a lot!
Re:Ask HN: What project did you tackle to learn C? by yitchelle on Monday February 12, 2018 @04:34PM (#16362455)
I created an inventory database for my dad's hardware store by in the late 1980s. It was on an Atari 520ST via Lattice C.
Re:Ask HN: What project did you tackle to learn C? by ioddly on Saturday February 10, 2018 @01:33PM (#16348718)
Lisp interpreter.

Writing a GC and tagged values in particular are where pointers and memory management finally really clicked with me.

Re:Ask HN: What project did you tackle to learn C? by Taniwha on Saturday February 10, 2018 @02:34PM (#16349067)
I ported V6 Unix to another platform ..... first I had to port the compiler ....
Re:Ask HN: What project did you tackle to learn C? by KasianFranks on Saturday February 10, 2018 @11:25AM (#16347940)
Re:Ask HN: What project did you tackle to learn C? by gjvc on Saturday February 10, 2018 @11:09AM (#16347865)
Writing a GUI version of PGP 2.6 for RISC OS, back in the day.
Re:Ask HN: What project did you tackle to learn C? by shortsightedsid on Saturday February 10, 2018 @11:08AM (#16347859)
Text Editor in College
Re:Ask HN: What project did you tackle to learn C? by halayli on Saturday February 10, 2018 @12:43PM (#16348435)
You don't need a project to tackle C. Start with "The C Programming Language" and do the exercises or "C How To Program" by Deitel & Deitel which also has plenty of exercises.
Re:Ask HN: What project did you tackle to learn C? by bonoetmalo on Saturday February 10, 2018 @12:52PM (#16348490)
I think the post is more asking "If you learn through projects, what project..."

Personally my attention span got completely shot once I graduated college and I can't learn for the sake of learning like you're suggesting anymore.

Re:Ask HN: What project did you tackle to learn C? by pvg on Saturday February 10, 2018 @11:12AM (#16347885)
RSA implementation for school science fair.
Re:Ask HN: What project did you tackle to learn C? by bluedino on Saturday February 10, 2018 @12:52PM (#16348488)
doom and quake level viewers, texture extractors, etc. c compiler in one hand and specs in the other
Re:Ask HN: What project did you tackle to learn C? by tomcam on Saturday February 10, 2018 @01:44PM (#16348780)
Wrote an in-memory compiler
Re:Ask HN: What project did you tackle to learn C? by hprotagonist on Saturday February 10, 2018 @11:11AM (#16347877)
a truly weird data munger that had to run on VxWorks.
Re:Ask HN: What project did you tackle to learn C? by rasengan on Saturday February 10, 2018 @01:15PM (#16348613)
IRC
Re:Ask HN: What project did you tackle to learn C? by throwAwaySSL on Saturday February 10, 2018 @11:19AM (#16347915)
OpenSSL
Re:Ask HN: What project did you tackle to learn C? by thr0w__4w4y on Sunday February 11, 2018 @03:55PM (#16354743)
I teach security, and that story (about EAY using OpenSSL as a project to learn C, because what could go wrong?) comes up every time.

For those who don't know the backstory (many here will) -- crypto is hard to implement correctly; protocols are hard to implement correctly; and C isn't the easiest language to use. [Disclaimer: I've used C "since forever", love it, and am pretty decent with it, but I've made my goofs. I've also implemented crypto & protocols myself, neither probably very well...]

Apparently in ~1995, Eric A. Young ("EAY") decided to implement his own SSL stack (called "SSLeay"), at least partially with the goal of learning the C programming language.

At some point, SSLeay became OpenSSL, EAY moved off the project, and OpenSSL went on to become a staple of network computer security (and insecurity).

I can't find a reference to back this up right now, but I know I've seen it in the past somewhere credible enough that I'm here repeating the folklore.