tags:

views:

226

answers:

6

I know there are many tutorials out there for getting started in C. However Its hard for me to apply the knowledge. The way I've always started out in languages is by writing scripts. Of course C is not a scripting language.

My question isn't so much about learning C as much as it is about how to get started applying C. Great I can write a temperature converter or a text-based rpg. Maybe its because in python I just write up the code in somefile.py and chmod +x somefile.py && somefile.py . I do not really have an equivalent process for C. Every time I read about C its a different compiling process with different flags. Can someone just give me some definite direction on best ways to apply C when you already work with higher-level dynamic scripting languages?

Btw. .. I'm asking about C and not C++.

I usually am on either OpenSuse 11 or Ubuntu 9.04 . "What compiler do i use" is part of the problem. In python there is no choice its just "python somefile.py" same with php or ruby. I didn't know there were choices.

A: 

The best advice I can give here is find a topic you're interested in, see if you can make a program to do what you want/assist in doing what you want/adding functionality to the interest of choice, and start coding.

This gives the bonus of doing something you're interested in, and at the same time making something that directly influences it. It should give the motivation to keep steaming onward with the learning process.

Kyle Rozendo
A: 

I'm working with C a lot at the moment with Linux Kernel modules and am relatively new to C. I've found this rewarding which I think is what's important for this sort of hobby 'temperature converter or a text-based rpg' type programming.

I also struggle finding an application of programming skills. Balance of challenge and reward is important I think.

cheesysam
+4  A: 

As rogeriopvl wrote in a comment, the compilation process is really simple. Just write up the code in somefile.c and

gcc -o somefile somefile.c && ./somefile

(if you're using GCC, and if not, your compiler of choice can probably be invoked similarly) Unless/until you start getting into more complicated projects, it's barely any more complicated than a scripting language. (Well... okay, you may need to link some libraries, once you get beyond the basics. But still, not a huge deal.)

In fact, I did write myself a little shell script that allows me to use C as a scripting language. But the process for setting it up is a little more complicated than what you may want to get into at this stage - it's simpler to just run the compiler each time. Still, if you're interested, I can look up the directions (for Linux) and put them here.

David Zaslavsky
Better yet, if your program doesn't require any external libraries or special flags (and if you're just starting out there's a good chance it won't) you can just write `make somefile` at the commandline and `make`'s implicit rules will call `cc -o somefile somefile.c` for you even though you don't have a `Makefile`.
hobbs
+2  A: 

C code needs to be compiled before the program can be run. The exact process is different depending on which platform and compiler you are working on.

For the most part, using an IDE (such as Visual studio, Eclipse, MonoDevelop, and a bunch of others) will do the nasty work for you so that you just have to press a button or click an icon. Download one of these

Isak Savo
+5  A: 

write w.c

#include <stdio.h>

int main(int argc, char *argv[]) {
 int i;
 for (i = 0; i < argc; ++i) {
  printf("Param %d is '%s'\n", i, argv[i]);
 }
 return 0;
}

and compile with

gcc -Wall -o w w.c

run

./w
agsamek
+1 for -Wall. I would also add -Wextra and -std=c99 to the mix.
Andrew Keeton
:) -Wall is a must
agsamek
+1  A: 

I asked myself this question when I was learning C. The problem here, if I can say this is a problem, is that C can be used in a broad range of applications and in a broad range of environments, which one with its own IDEs or compilers and libraries. Some examples where you can use C for real staff.

Embedded software. In this case you will probably use some lib.

Network programming (take a look at this book.

Device driver development.

Libraries (both for Linux/Windows and other OSs)

Well this list is endless.

O don't know if I help you with this question. If you give more details about what are you interested in, could be helpful

Good luck

Andres