views:

1890

answers:

37

I'm learning the C language on my Mac with Xcode.

I've created a "Hello World" app, and played around with simple maths.

What should be my next goal? If someone was to ask me about PHP for example, I'd say "build a basic blog software". Can someone point me in what would be a great learning experience for someone new to C? One that will test a lot of the static types, etc

It should also be < 1 week to create. It does not need to be useful.

+6  A: 

Hi

create a calculator.

masoud ramezani
you can use linked list for implementing this.
masoud ramezani
you can use tree data structure at this app.
masoud ramezani
+7  A: 

Writing something that isn't useful is not what programming is about - I can't imagine doing such a thing myself, except for one or two liners to test a specific feature. Identify a problem you or your colleagues/friends are having, and write a C program to solve it. That way you are motivated to do good work.

And to prove I'm not blowing hot air, the first C program I wrote after "hello world" was a Unix printer filter to output APL programs on a dot-matrix printer, required by an academic I worked with.

anon
So using Project Euler to learn a new language is not a good idea? You don't always have to write useful programs.
ChaosPandion
Bleh. Can't say how much I disagree with this.
Beska
@ChaosPandion You are right - I don't think it is very useful. Doing basically maths based problems is not going to teach you much about how to use a general-purpose programming language. Most programming has very little to do with mathematics.
anon
i agree with the fact that if you program something useful for others you will be much more motivated to work through until the end and deliver quality and do it in less time + you will have to deal with a lot more details and aspects of programming than you would otherwise.
Emile Vrijdags
I would claim the opposite. Programming is primarily about having fun. The usefulness only developed out of it accidentally. When starting to program, do fun things, not useful things. My opinion.
Konrad Rudolph
Actually, many Euler (or topcoder, etc) problems begin to require knowledge of algorithms to do efficiently (or at all). Day to day programming problems you're likely to find at work may never expose you to this. Many of these algorithms are very good to know for 'useful' programming... you'll never realize what you don't know until you explore.
darron
@Konrad, because its useful doesn't mean it isnt fun, for me its more fun to make something useful because of the thankful reactions I get. I think it comes from the desire to help other ppl, and of course the egocentric desire to be admired and get thanks (why are we all here trying to answer questions?). So that is surplus fun added to the fun of making the program itself == even more fun
Emile Vrijdags
+4  A: 

My first C program (after "Hello World") was a text editor. Took about one week with 2 people working on it. You could start simpler with a Unix like command line tool, for example something like grep but with a lot less features of course (a fully functional grep is not easy to implement!).

Maurits Rijk
what was the user interface in? curses, gtk+... etc
Matt Joiner
This was back in 1988 or 1989. We started development on an Atari ST and later ported to a PC. User interface: low level screen positioning, not portable at all ;)
Maurits Rijk
In addition, the GoF (http://en.wikipedia.org/wiki/Design_Patterns_(book)) use a text editor application to learn patterns.
Aito
+6  A: 

A tic tac toe game.
And don't forget to let the computer say "A strange game. The only winning move is not to play" every once in a while.

VolkerK
+1 for WarGames quote :)
alex
this movie is awesome!
born to hula
+9  A: 

I would suggest trying to write simple game like Buls and Cows or Tic-tac-toe ;)

Alexander Vakrilov
Would the layout of the Tic Tac Toe (the #) just be ASCII art for simplicity?
alex
For the first implementation, yes. Then if you want to learn how to make a UI in C...
Brian
Simple games are a great way to explore programming and keep yourself interested in going further.
darron
+1  A: 

Like masoud ramezani said you can try making a calculator, or perhaps some simple games like Tic Tac Toe(maybe create an AI for it too) or Hangman. Also, try solving some of the problems at Project Euler it really helped me with using big numbers.

Erethon
+4  A: 

Make a ToDo list (that's something useful).

Some features it might have

  • Add/delete tasks
  • Sort by categories/tags/priority
  • Reminders

You would learn alot from this little project and you might even end up using it. Good luck! :)

Axsuul
+26  A: 

Write a linked list. That will give you the opportunity to learn how to use pointers.

villintehaspam
Good idea indeed. Make it a doubly linked one and also write an iterator to traverse the list and insert/delete items in between
Trap
And use the XOR-ed pointer trick. This is C after all. Use its strengths.
finnw
@finnw: The (http://en.wikipedia.org/wiki/XOR_linked_list) XOR-ed pointer trick is a clever optimization, but not a particularly educational one.
Brian
+10  A: 

Few Ideas :

  • Matrix Multiplier (Given 2 matrices and their dimensions, you need to multiply them)
  • Simple Calculator with file writing and reading (Perhaps with pointers)
  • Fibonacci series generator (Given the number of terms, you need to print the series)
  • A program to detect prime numbers. (Given a number you need to check whether a prime or not)
  • Leap year detector (Given a year, check whether it is leap year or not)

Those ideas will help to learn C + it will help you to improve your algorithm/problem solving skills.

Chathuranga Chandrasekara
I learned much of my early C skills by writing myself a small library of (relatively simple) math and utility functions like these
bta
+28  A: 

Create a Conway's Game of Life. It's interesting and educational.

Daniel Daranas
See also http://stackoverflow.com/questions/1823/writing-a-conways-game-of-life-program
Daniel Daranas
I've been programming a long time and haven't done that! It's about time I try my hand at it!
Earlz
That's an awesome idea. And very interesting :)
alex
Nathon
+10  A: 

Write a Brainfuck interpreter.

It'll teach you about pointers, file IO, looping, conditionals, data structures (if you choose to use a stack rather than recursion)

I did it when I was learning C and it was a fantastic way to get up to speed.

Charlie Somerville
Probably deserves a link, newbies might be confused by the title: http://en.m.wikipedia.org/wiki/Brainfuck
Rob Keniger
Someone flagged this as offensive, LoL!
S.Mark
@S.Mark Likely due to the confusing language-name. I too would have considered this inappropriate had I not known better.
Jonathan Sampson
or Forth. Warning , writing languages etc can get very addictive
pm100
+3  A: 

Write something useful... that way you get to learn how to debug C, which is the hard part of the language.

For example, my first C program controlled a spectrograph and got data out of the photometer attached to it; two device drivers and a user interface, basically. I needed it, so I figured out how to make it work reliably.

My second C program took those spectra and measured various things about them... it was nearly 10000 lines and ran for about a month on the hardware of the day.

Point is, if you need what the program does, you'll learn far more about the language and environment.

Andrew McGregor
+14  A: 

Write a command line based text encoding converter. There is everything in it:

  • File I/O.
  • Memory handling (of course it should handle arbitrary line lengths without buffer overflows and without leaks).
  • String handling.
  • Different integer types (to handle UTF-8/16/32).
  • A loooot of knowledge about text encodings that is relevant in the real world.
  • Command line argument parsing to allow to make the thing scriptable.
  • Probability (how to detect the encoding when there is no BOM).

Plus, you can begin with little parts (for example, convert line-end encodings for the standard charset between different systems) and then go on to the bigger parts (read in UTF-16BE and write out 8 bit ASCII in ISO/IEC 8859-2, properly caring for characters not encodable in the target charset).

Secure
Do you have any recommended reading on this? Thanks.
alex
You could begin here: http://en.wikipedia.org/wiki/Character_encoding and then click your way along. But admittedly this may be a project that most likely takes more than one week when you want to do it in-depth. For the "little part", here is a starter: http://en.wikipedia.org/wiki/End_of_line
Secure
+1  A: 

Make contacts application - stores data to file. Enjoy C!

Krunal
+1  A: 

I'm going to go out on a limb and say Twitter client. Working on a twitter client would allow you to concentrate on Model, View, Controller design, interacting with web applications, storing and clearing data using appropriate Mac OS X APIs, etc.

David Rouse
Yeah of course. Hello world, followed straight away by jumping into MVC, HTTP, etc. Then I guess a 3rd project would a be a new OS.
John
+4  A: 

since "hello world" was your last project I would then progress to...

1)getting familiar with connecting to a database.

2)Start working with the graphics library.

3)Become familiar with different collections Linklists, hash tables arrays etc.

fishhead
I think 1) is an excellent idea. I'd recommend trying to write a program that interacts with sqlite since you don't have to mess around with configuring a server.
Bryan Oakley
Wouldn't it be better to learn what you can do with the language on its own first before moving onto using external libraries for databases and graphics?
Tom Savage
That's part of learning the language. In my world I have never worked with an app that didn't connect to a database.It's a real world situation. Graphics...graphics are a lot of fun.
fishhead
A: 

Have a look at basic data structures like single and double linked lists, binary trees, stacks, queues etc. You will learn about pointers and recursion. Also try to implement simple sorting and searching algorithms.

Fair Dinkum Thinkum
+2  A: 

I was teaching and for some time, a biorhythm software was one of the first larger assignments.

Shimodax
+2  A: 

Work your way through all the examples in the book Software Tools. I remember doing that very early in my career and it made a huge difference in how I write code.

Bryan Oakley
+1  A: 

Four in a row is a nice one that requires to dip into various parts of a programming language (2-dimensional arrays for example)

+2  A: 

A database engine, where you can store data in files. Then you can improve it with:

  • a language parser to retrieve data (like sql) to learn string functions.
  • data structures and algorithms (tree, index, sorting).
  • client/server connection (sockets)

I hope it helps you

Aito
He's looking for first app after "Hello World", this one is too complicated.
tomp
+2  A: 

I've frequently found a hex dumper (display contents of file in hex) to be a useful thing to build, since it touches on a lot of simple but different ideas.

An Onion That is Red
A: 

I found that I didn't understand what the fuss was about with the whole programming thing until I wrote a program that took arguments and did something them useful. what ever it is you should write something that can grow.

  • command line calculator for simple math ie 2+2
    • command line calculator that can handle complex expressions ie 3 +5 * (2 +4) preserving order of operations
      • Command line Calculator that can solve for x
  • A command line ping program
    • A command line Mail cleinet for text
      • Command line mail client that can send attacments
rerun
A: 

Anything that involves saving stuff to a file and loading it again... focus on how to do real-world stuff.

John
+1  A: 

Pick a problem that you would love to see if you can solve - programming is a lot about scratching your own itch and keeping your enthusiasm up. Take something relatively small and well-defined, that is possible to finish.

What's doable or not depends entirely on your background. A small file utility, like a rudimentary grep implementation? Display the contents of a file in hex? One of the Euler problems? Implementation of some simple network protocol client/server?

Just a few weeks ago I decided to practice C by writing a Sudoku solver - it turned out ok and I got to try out bit arithmetics, pointers and memory handling...

Anders Lindahl
A: 

The best assignment I ever heard from one of my professors back in bachelor: Write a console application that will load a bitmap, convert it to black/white and display it as 0 and 1 in console. The entire bitmap reading functionality must be done manually.

Victor Hurdugaci
A: 

You can try to implement some functions from the standard library on your own, for example your own strlen. As you learn about the language itself, you'll be learning it's standard library too. You should also try to implement some common data structures, like stacks or linked lists, especially if you're already familiar with them. None of these will take too much time, they'll probably be fun to do, and you'll learn a lot. And don't rush it : C is a simple language, syntactically, but getting something to work as it should in C is no easy task, especially if you're completely new to it. You'll see your share of segfaults and seemingly random errors, so don't get discouraged.

PS : You should probably also learn to use a debugger early on, it will save you a lot of frustration

fingerprint211b
+3  A: 

Go buy The C Programming Language and create every example in it.

kubi
A: 

Calory calculator, unique words dictionary generator (from an input file), currency converter, Simple language interpreter, Config file parser/generator (like .ini), shopping list tool, simple contacts management application, crossword, simple archiver: searches for frequently used words in the text and replaces them with something shorter (don't forget about decompression ;) )

Good luck

opal
+1  A: 

Try and inventory control system. These always seemed to be the "next" step in most programming classes i took in high school and college. if you want a challenge try and write a parser/tokenizer. With Perl, Ruby, Python, and other modern languages we often take it for granted but there's a lot to be learned by doing this in "C"

BandsOnABudget
A: 

develop a chess game.

Athens
+1  A: 

My first VB.net program, after Hello World, was a TXT to CSV converter. I was given a batch of text files set out as spreadsheets, using spaces to make fixed-width columns, like this:

Column 1        Column 2        Column 3               Column 4
     235          242532        sometext   32532532543690890807
  453e43                    somemoretext          4534643463643
(etc)

I needed to convert hundreds of these TXT files into CSVs, so they could be used in Excel. It taught me a lot about arrays, splitting, reading and writing to the filesystem, etc, among other things. There was also additional unwanted header information such as addresses, etc, which varied from file to file, so I had to make sure they got cut out. You might want to try something similar in C.

Auguste
A: 

Go find some open bugs in some open source code and fix it. Start with an easy bug.

Choose a serious program and you'll learn how to write scalable code & pick up some really cool techniques.

While you're doing that, keep a list of any tasks that you feel are a waste fo your valuble time and could be done easily if someone would only write a program.

Shandy
A: 

A google clone, of course. Or amazon.com clone. Or maybe an operating system...?

Aim for the stars...

KristoferA - Huagati.com
+1  A: 

If you want to progress to something ever-so-slightly more complicated than "Hello World", you could try "FizzBuzz", as described in a coding horror post:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

It's not on the scale of building a blog, but it will teach you about loops and conditional operators.

CodeSavvyGeek
A: 

Try a Geek Code generator/decoder.

Auguste
A: 

I suggest to create a console application which get some numeric input and sort them in a linked list.

when finish this, you can change the way you sort the linked list.

Nasser Hadjloo