@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.
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.
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.
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.
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' :).
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).
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:
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.
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.
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.
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.
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...
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.
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.
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+.
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.
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.
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
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.
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).
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.