8 ms·
Ask HN: What project did you tackle to learn C?
- jacquesm 9y agoMy 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.
- DamonHD 9y agoA robotics operating system for the Z80 ~32 years ago!
- karimf 9y agoI 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.
- shortsightedsid 9y agoText Editor in College
- gjvc 9y agoWriting a GUI version of PGP 2.6 for RISC OS, back in the day.
- cf 9y agoI 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.
- Stwerner 9y agoI 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=PLZ1QII7yudbc-Ky058TEaOstZHVbT-2hg https://www.youtube.com/watch?v=bGAfaepBco4&list=PLZ1QII7yud...
- hprotagonist 9y agoa truly weird data munger that had to run on VxWorks.
- pvg 9y agoRSA implementation for school science fair.
- gespadas 9y agoA mimic OS GUI (a couple of windows, buttons, wallpaper changer, etc). It was really fun to code it... over 2 decades ago.
- throwAwaySSL 9y agoOpenSSL
- thr0w__4w4y 9y agoI 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.
- Hnrobert42 9y agoA 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.
- TeMPOraL 9y agoA 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=PA130&dq=prhreads&source=bl&ots=VUKSQ_nmzP&sig=6h9sMBdpD_3HVGAHEiohl2_4-jM&hl=en&sa=X&ved=0ahUKEwjKurLm6ZvZAhXI16QKHbNTAeYQ6AEIKzAA#v=onepage&q=prhreads&f=false https://books.google.pl/books?id=xzbRQXXsy6UC&pg=PA130&lpg=P...
- Hnrobert42 9y agoSorry. Typo.
- codingdave 9y agoA 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.
- KasianFranks 9y agotsearch.c https://searchcode.com/codesearch/view/20342823/ https://searchcode.com/codesearch/view/20342823/
- aiansiti 9y agoA followed the crafting interpreters series but reimplemented the python in c. Really gave me an appreciation for high level languages...
- shiado 9y agoI 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.
- krylon 9y agoWhen 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).
- berbec 9y agoI 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.
- jschwartzi 9y agoI 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.
- mettamage 9y agoI 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.
- peterburkimsher 9y agoA 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.
- ateesdalejr 9y agoSounds like a vulnerability waiting to happen.
- theparanoid 9y agoGuess 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?).
- dahart 9y ago@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.
- mikerg87 9y agoI 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.
- sleavey 9y agoA microcontroller with temperature, humidity, pressure, dust and light sensors, and an ethernet web interface. I learned a lot!
- __s 9y agoBrute force solutions were becoming too slow for https://projecteuler.net https://projecteuler.net in Python, but with C I could put off being clever about the math
- sifoo 9y agoToo many to list, but I think it's safe to say I learned most from implementing my own languages. The latest one might be of interest if you want something small enough to own but interesting enough to stay motivated: https://github.com/basic-gongfu/cixl https://github.com/basic-gongfu/cixl
- ktpsns 9y agoMy 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.
- snissn 9y agoFirst 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
- sidlls 9y agoScientific instrument device drivers and software with network and data reduction libraries to coordinate their activities and data collection in different locations on the planet.
- pjc50 9y agoGames. 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.
- halayli 9y agoYou 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.
- bonoetmalo 9y agoI 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.
- bluedino 9y agodoom and quake level viewers, texture extractors, etc. c compiler in one hand and specs in the other
- drdebug 9y agoI 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...
- viperscape 9y agoI 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.
- malkia 9y agoI'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).
- danieldk 9y agoThen 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 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.
- ioddly 9y agoLisp interpreter. Writing a GC and tagged values in particular are where pointers and memory management finally really clicked with me.
- jehna1 9y agoWanted 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 https://github.com/jehna/nes-bootstrap
- sonnynomnom 9y agoHere's a repo that has 50+ C projects (in order of difficulty): https://github.com/sonnynomnom/Introduction-to-Programming-in-C https://github.com/sonnynomnom/Introduction-to-Programming-i... You should "star" it to bookmark it as more things like slides and videos will be uploaded this month.
- rasengan 9y agoIRC
- marmaduke 9y agoI wrote a toolkit for stochastic differential equations, but I got bogged down trying to emulate virtual methods and inheritance, badly.
- mattmoss 9y agoI 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.
- markbnj 9y agoI 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+.
- tomcam 9y agoWrote an in-memory compiler
- Taniwha 9y agoI ported V6 Unix to another platform ..... first I had to port the compiler ....
- bradknowles 9y agoMy 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.
- yitchelle 9y agoI created an inventory database for my dad's hardware store by in the late 1980s. It was on an Atari 520ST via Lattice C.