8

I've took C programming class while back ago. Since I'm done with the class and don't have any access to the school lab anymore, can anybody give me suggestion how do I practice my c at home. Thanks

12 Answers 12

10

Code a little game like tic-tac-toe or pong. Lots of fun and a sense of accomplishment when you are done, but complex enough to keep you working at it for a while :)

There are also code competition sites like topcode at google and such to keep practiced. Heck, code kata could help as well. Like playing an instrument, you must keep practicing to get better. Ideally, you'd get an entry level / internship position to further improve your abilities under a mentorship.

If you lack a compiler, microsoft has a free version of the latest dev studio available for download. It can do c, c++, c# and anything in between. Also, the suggestion of gcc is a good one as it is widely used in various open source developments over at source forge - another place to go and sign up for a project and help out a group project.

9

Try solving some ACM programming contest problems using C.

http://acm.uva.es/

Writing code for the judge and submitting it is lots of fun.

2
  • You should update the link, they have a new homepage (that is much more pleasant to the eye): uva.onlinejudge.org
    – nico
    May 20, 2010 at 6:26
  • 1
    spoj.pl is a good place too. One thing that will both challenge and interest you is to see your code run, earn points and may be compete with others. There should be plenty of good School level competitions (most of which are online), participate in a few.
    – Shravan
    May 20, 2010 at 6:58
4

I assume you have a computer at home. Is your question about access to software? If it is Mac or Linux, then it already has a gcc compiler. For Windows, you can download mingw or cygwin. I believe Microsoft also have a free version of it Visual C++ for download.

2
  • Technically, a fresh install on a Mac doesn't come with the gcc compiler installed last time I checked. It is on the install disc though under optional installs or you can just download the latest version of Xcode to get it. Same thing with Ubuntu, one of the most popular Linux distros, you cannot start compiling C programs with a fresh install and need to download/install it. Anyways, I recommend MS C++ on Windows. microsoft.com/express/downloads/#2010-Visual-CPP It is free if you get a registration key.
    – daveangel
    May 20, 2010 at 11:10
  • That's true. I misspoken about Mac. You have to download xcode to get it. May 20, 2010 at 14:13
3

The best way to learn a programming language is to use it. Many times at home you sit there and realize that there is some utility that you could write that will make your life easier.

I don't recommend coding games that require an API or such as it will just confuse the matter. You would ideally like to learn the language a bit better before attempting to learn a Graphics API.

3

The first c exercise I had fun with is solving a maze. A maze looks like this

********** 0
* *  *B  * 1
* * **** * 2
* * *    * 3
* * * ** * 4
*A    *  * 5
********** 6
0123456789

so on a 10 x 7 array, A is the staring point (column 1, row 5) , B is the destination. * is wall and space is road. The objective of the program is to print every coordinates of the shortest path from A to B, e.g. 1,5 -> 2,5 -> 3,5 -> 3,4 -> ...

if you are looking for a compiler, MingGW is free on Windows.

3

Your question may be understood in several ways:

You don't know how to have an environment to deal with C at home

This is partly a matter of opinion, but especially for C, I think linux is a good environment. C and Unix are tied together after all. You will need gcc, make, etc... I remember when I started learning C as my first programming language at school, nothing made much sense (separate compilation, linking, make, etc...), and I don't know where you at there.

You want a project to practice C at home

I will assume you know how to use a typical environment to build C software. I think the best is to get into an open source project. C is a widely used language in open source, and finding a project which is both interesting to you and in need of manpower should not be difficult. Starting a project from scratch is what you do at school, and getting into a "real" project will make you learn much more useful thing than doing the same thing at home - dealing with source control, dealing with bug tracking, dealing with people :) There is a steeper learning curve, if only to get involved in the project proper, but I think it is much more rewarding, especially if it is a widely used project.

C is usually used for low level stuff, but besides obvious (and rather difficult) things like the kernel, there are language runtimes (diving into Python C code for example is not too difficult), audio/video editors (ardour, etc...), etc...

1

Just write and run C programs at home, how else would you practice? ;-)

I suspect that, although you didn't say so, you're wondering about how you can get the necessary tools to compile a C program on your own computer - am I correct? If that's the case, know that all the tools you need to develop C programs are available online for free. The most important is a compiler, of course, and one of the most popular compilers is GCC. If your computer runs Windows, I think you can also download Microsoft's Visual Studio for free (or some edition of it, at least), and I believe that would include a C compiler.

You'll also need an editor or IDE. At a bare minimum you could do it in Notepad, but that's inflicting unnecessary pain on yourself. Notepad++ is a popular alternative that's good for programming. Or if you're using Visual Studio, that has its own editor. (Actually VS has pretty much everything you need, as far as I know - I haven't used it much myself)

1

See c-on-visual-studio for discussion of the Windows environment. Microsoft provides a free version of visual studio, Visual C++ 2010 Express.

1

Supplementing the other answers, if you're on a beefy Windows machine you can run something like Ubuntu in a virtual environment like VirtualBox to get a sandbox that's built to run C programs.

2
  • Sure, you may not want to practice C in a windows machine. Or, perhaps avoiding blue screens is your reward for doing it right ;)
    – Chubas
    May 20, 2010 at 6:03
  • 2
    However, since memory management has been quite improved since win98, you will have a hard time provoking a bluescreen by coding c on win 2k-xp-vista-7. May 20, 2010 at 6:56
1

Install ubuntu or debian. After installation do:

sudo aptitude install gcc

Or alternatively install some other C compiler.

Now you're capable of compiling C source code to binary which you can run.

Consult the manual of your compiler for usage and learn how to write shell scripts for constructing build-scripts.

1
  • 1
    This may be totally unnecessary depending on what Linux distro you've installed. Type gcc or cc on a command line to see if there is already a C compiler installed.
    – daveangel
    May 20, 2010 at 11:18
-1

Begin with solving basic level logical questions, and while solving always follow the best approach and best practices.

You can refer and try solving these fundamental question : C programs

Also try solving questions of : Project Eulers

-1

A really good way to exercise C is to read (or reread) The C Programming Language (K&R) and to do every exercise at the end of each chapter.

Not the answer you're looking for? Browse other questions tagged or ask your own question.