You are not logged in.

#1 2010-07-12 15:26:51

alf
Member
From: Tromsø, Norway
Registered: 2010-07-05
Posts: 35

Learning C, but cant get started without..

.. a workbench/compiler!

So I decided that it would be a good idea for me to finally take the step into the underworld and learn some programming!
I've picked up 3 books on C programming, and I'm ready to start, and i'm eager too!

The problem is that I apparently need a workbench and a compiler to get started.
Would anyone here be kind enough to give me a push, so I can get started? smile
I'd like something noob-friendly, that aint too complicated. I just wanna get started on the coding and testing!
A workbench and a compiler combined in the same program would be nice too smile

Thanks in advance for any useful answers big_smile

Offline

#2 2010-07-12 15:34:32

Cyrusm
Member
From: Bozeman, MT
Registered: 2007-11-15
Posts: 1,053

Re: Learning C, but cant get started without..

the standard for compiling C programs on linux is gcc (the GNU C compiler)  which you probably already have installed on your system. (pacman -Q gcc will let you know if it's installed, pacman -S gcc will install it if it isn't)  From here, you can just write code using a text editor, and then compile it with gcc.  there are countless online tutorials to get you started with this process.  also, look into using gnu make. it makes building your program much easier!!! 

and as far as a workbench is concerned, I'm assuming you mean in IDE (integrated development environment)  to help you with organization/debugging/and whatnot? try Eclipse with the eclipse-cdt plugin.  I've never used eclipse for C development, but it works great for Java.  I do all of my coding in C just using Vim/gcc and sometimes gdb (the Gnu Debugger)  for debugging.

Here's a great list of resources from one of my instructors web sites http://www.cs.montana.edu/courses/201/WebRefs.htm

Last edited by Cyrusm (2010-07-12 15:36:28)


Hofstadter's Law:
           It always takes longer than you expect, even when you take into account Hofstadter's Law.

Offline

#3 2010-07-12 15:38:53

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: Learning C, but cant get started without..

Curious what books you've chosen. imo, if one of them isn't the white bible (K&R 2), then you're missing out and perhaps even doing yourself a disservice.

Offline

#4 2010-07-12 15:49:01

alf
Member
From: Tromsø, Norway
Registered: 2010-07-05
Posts: 35

Re: Learning C, but cant get started without..

The 3 books are:
- Introduction to computing systems (from bits & gates to C & beyond) second edition, written by yale n. patt and sanjay j. patel
This is the book I primarally am going to use.

- The C programming language ANSI C second edition, written by Brian W. Kernighan and Dennis M. Ritchie. It's white, and people have been refering to it as some bible, but i dno if this is the one you're talking about.

- Problem solving and program design in C, fourth edition, international ideition. Written by Jeri R. Hanly and Elliot B. Koffman

As for the eclipse workbench, my father (who has done very simple C programming), told me to maybe get something a little more simple. Also i was adviced to stay away from text editors for coding, as it's much easier with a workbench.

Thanks smile

Last edited by alf (2010-07-12 15:51:06)

Offline

#5 2010-07-12 15:55:52

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Learning C, but cant get started without..

I don't recommend a "workbench" or IDE to learn C in Linux. In my opinion it makes learning C more complicated that it needs to be. I find all of the settings in an IDE to be confusing and time consuming.

Here is an example on how to compile an application without using an IDE:

1) Write some C code in a file named "code.c". (of course, you can name the file anything you want)

2) Compile it by using the command line.

gcc -o run_me code.c

3) Run your new application. It's called "run_me".

That's it.

What were the reasons you heard that makes using an IDE easier than a simple text editor?

Last edited by drcouzelis (2010-07-12 16:00:15)

Offline

#6 2010-07-12 15:59:53

alf
Member
From: Tromsø, Norway
Registered: 2010-07-05
Posts: 35

Re: Learning C, but cant get started without..

automatic organizing, with inlets and coloured code, mainly. And the fact that it recognizes if the code is wrong somewhere.

thats all that i want tongue so very lightweight and userfriendly i guess.

Last edited by alf (2010-07-12 16:00:20)

Offline

#7 2010-07-12 16:06:47

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Learning C, but cant get started without..

alf wrote:

automatic organizing, with inlets and coloured code, mainly. And the fact that it recognizes if the code is wrong somewhere.

Many many text editors (maybe most) have syntax highlighting ("coloured code"). (see http://en.wikipedia.org/wiki/Comparison … g_features)

What do you want to automatically organize?

I'm sorry, I don't know what an inlet is.

C has been my favorite language for many years. Have you decided what your first project will be? smile

Oh! I forgot to ask you. Is C the first programming language you are learning?

Last edited by drcouzelis (2010-07-12 16:07:40)

Offline

#8 2010-07-12 16:11:55

alf
Member
From: Tromsø, Norway
Registered: 2010-07-05
Posts: 35

Re: Learning C, but cant get started without..

Oh maybe i'm using the wrong word (inlet).
You know when text goes like this:
aaaa something related belooooow
{         
          codecode
          code ceode
}

Yeah C is the first language. so my first project will be something simple. Probably some pingpong game or something.
That's if you dont count the examples in the books, ofc i'm going to start with the hello, world. It's a long way to go, but heck I wanna learn this.
The text won't be hello, world though. It'll probably be something like "alf is superawesome, cuz he can make this"

Offline

#9 2010-07-12 16:13:14

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: Learning C, but cant get started without..

The C Programming Language is the white bible.  You will also hear it referred to as K&R2.  "K&R C" most often refers to the language described by the first edition of The C Programming Language, which is pre-standard and should not be used for new projects.

alf wrote:

Also i was adviced to stay away from text editors for coding, as it's much easier with a workbench.

Terminology first:  you seem to be using "workbench" as a synonym for "IDE".  I'm sure there's nothing wrong with that, but it's rather unusual in this neck of the woods and you might want to steer clear of it.  On topic, I've never used an IDE for C and my considered opinion is that they obstruct learning.  Pushing a magic button will not show you how to use a C compiler.  Furthermore, for small, one- or two-file projects of the type you are likely to be writing for quite a while, an IDE is way overkill and complicates the compilation unnecessarily.  Of course, you're free to use whatever you want.  If you're looking for an editor, I can recommend both jEdit (intuitive, mouse-driven programming editor) and Vim (more advanced and powerful features).

On another note, are you completely new to programming?  Because C isn't something that most people can just pick up without prior experience.  I certainly couldn't.  My typical recommendation is to learn Python and/or Perl first.  (My own first language was Java, but I don't recommend that to newbies at all.)

Offline

#10 2010-07-12 16:14:02

Google
Member
From: Mountain View, California
Registered: 2010-05-31
Posts: 484
Website

Re: Learning C, but cant get started without..

GCC for C
G++ for C++

Vim for all.

Offline

#11 2010-07-12 16:18:56

alf
Member
From: Tromsø, Norway
Registered: 2010-07-05
Posts: 35

Re: Learning C, but cant get started without..

yeah, i'm completely new to programming, and C will be my first language.
I think it'll be okay, as I pick up things quickly, even though the learning curve may be hard to overcome.
As for the IDE/workbench thing. Sorry for the misunderstandings, and thanks for clearing that up smile
I have a question then. Should i just stay to a text editor for now to code my C?
is jEdit some kinda text editor, that's nice to do C beginner stuff with? also, would i then use jEdite AND vim?
Can i just use gedit? tongue

nano seems to be out of question.

Offline

#12 2010-07-12 16:21:57

saline
Member
Registered: 2010-02-20
Posts: 86

Re: Learning C, but cant get started without..

I would recommend vim as the editor (start with vimtutor if you are unfamiliar).  As Trent said, magic buttons are harmful for learning.  vimtutor will take you throught enough basics to use vim well and vim has enough features to turn on later that you won't need to switch to an IDE.

and K&R2 is a gem...

Offline

#13 2010-07-12 16:29:57

Zeist
Arch Linux f@h Team Member
Registered: 2008-07-04
Posts: 532

Re: Learning C, but cant get started without..

Vim is the most awesome thing there is for code editing.

Any text editor will work however, and some people do seem to like to use big IDEs like Eclipse, KDevelop or Anjuta.

I prefer to see Vim with plugins as a "build your own IDE" that you can customise exactly to your needs which makes it far more flexible to me than anything else.


I haven't lost my mind; I have a tape back-up somewhere.
Twitter

Offline

#14 2010-07-12 16:45:17

alf
Member
From: Tromsø, Norway
Registered: 2010-07-05
Posts: 35

Re: Learning C, but cant get started without..

Ok i'll look into vim then! big_smile
wish me luck as I dive into the sea of programming!

Offline

#15 2010-07-12 16:46:01

Google
Member
From: Mountain View, California
Registered: 2010-05-31
Posts: 484
Website

Re: Learning C, but cant get started without..

saline wrote:

I would recommend vim as the editor (start with vimtutor if you are unfamiliar).  As Trent said, magic buttons are harmful for learning.  vimtutor will take you throught enough basics to use vim well and vim has enough features to turn on later that you won't need to switch to an IDE.

and K&R2 is a gem...

This! This!

Yes it's useful, but the more automated stuff you use, the less of the whole picture you are seeing.

It does feel like doing things the hard way when you compile on the command line, it does take longer than clicking a button, but in the end you are seeing things through the whole process and learning more.

Avoid automated stuff until you have a solid understanding of everything, or most of everything.

Offline

#16 2010-07-12 16:48:14

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Learning C, but cant get started without..

Yes, you can use Gedit. I recommend it.

If you don't know how to use Vim then I don't recommend you learn it now. That's too many things to learn at once! But in the future I recommend learning Vim. It's my favorite text editor. wink

Offline

#17 2010-07-12 16:51:37

Zeist
Arch Linux f@h Team Member
Registered: 2008-07-04
Posts: 532

Re: Learning C, but cant get started without..

Google wrote:
saline wrote:

I would recommend vim as the editor (start with vimtutor if you are unfamiliar).  As Trent said, magic buttons are harmful for learning.  vimtutor will take you throught enough basics to use vim well and vim has enough features to turn on later that you won't need to switch to an IDE.

and K&R2 is a gem...

This! This!

Yes it's useful, but the more automated stuff you use, the less of the whole picture you are seeing.

It does feel like doing things the hard way when you compile on the command line, it does take longer than clicking a button, but in the end you are seeing things through the whole process and learning more.

Avoid automated stuff until you have a solid understanding of everything, or most of everything.

I must say that I've actually met people who are second year CS students that don't know what the Linker is or what it does just because they have only used Visual Studio and there they just hit F5 and their program either runs or it doesn't and they've never learned how any of it works.

These are the people that then go out into the world and put out huge atrocities of software that barely works and that is incredibly inefficient. This is yet another reason why friends don't let friends use Visual Studio.


I haven't lost my mind; I have a tape back-up somewhere.
Twitter

Offline

#18 2010-07-12 16:54:21

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: Learning C, but cant get started without..

jEdit, Vim, and gedit are all text editors, as are Kate, nano, vi, emacs, joe, jed, Notepad and hundreds of others.  You need only one editor to write code, but it doesn't matter much which one you choose, as long as you are comfortable with it.  Vim and jEdit are those I have used most; the features I like best are automatic indentation and syntax highlighting for multiple languages[1].  I've not used gedit and have no idea what good features it may or may not have, but sure, you can use it if you like.

[1] One of my beefs with IDEs is that they're most often usable with only a few languages.  A good editor will highlight code appropriately for Perl, Python, C, Java, etc. and be able to set rules individually for each file type (e.g., I don't want my Python files indented exactly the same as my C files).

You wonder, "Should I just stay to a text editor for now?"  But that's really a matter of opinion.  Here on the Arch Linux forums people lean toward the text-editor-plus-compiler approach; it's part of the KISS philosophy that people here are attracted to.  Asking somewhere else might get you a different answer.  What it boils down to is this:  Use what you like, and let the rest of the world, well, you know.  We can give advice and tell what works for us, but we can't provide you with all the solutions.  (Well, I can, but you might not like them much. wink)

Vim can be hard at first, but vimtutor will get you well on your way to mastery, and its more advanced features are invaluable.  Really.

A final note:  Always, always, always enable warnings when coding.  With C this means using a compiler line like

gcc -Wall -Wextra -std=c99 -pedantic -o run_me code.c

They'll catch things like forgetting to #include certain headers, failing to return a value at the end of a function, passing the wrong argument to printf, and lots more.  I use std=c99 as an example; you can use -std=c89 to match the language of K&R2 (but really, the differences are pretty small).  Now, to be honest, that's more typing than I care to do, so I do

alias cc="gcc -Wall -Wextra -std=c99 -pedantic"
cc -o run_me code.c

which is much nicer.  You can put the alias line in .bashrc to avoid typing it every time you start a new shell.

Offline

#19 2010-07-12 16:55:59

alf
Member
From: Tromsø, Norway
Registered: 2010-07-05
Posts: 35

Re: Learning C, but cant get started without..

Hehe, okay. I'll use gedit or jedit, as it's by far the easiest to use. But will it detect the codes, and organize text with inlets?
Also, do i need to "tell" gedit to use c language instead of java? roll

Last edited by alf (2010-07-12 16:59:12)

Offline

#20 2010-07-12 17:08:49

Trent
Member
From: Baltimore, MD (US)
Registered: 2009-04-16
Posts: 990

Re: Learning C, but cant get started without..

When you first start it up to create a new C file, you'll need to save the new file with a .c extension before jEdit will use C highlighting: just hit Ctrl-S (save) and type "somefilenamehere.c" in the File Name box.  After that you will have C syntax highlighting turned on whenever you open the file.  And yes, it will indent the code for you.

Offline

#21 2010-07-12 17:21:53

alf
Member
From: Tromsø, Norway
Registered: 2010-07-05
Posts: 35

Re: Learning C, but cant get started without..

Okay, awesome!
You guys are awesome, the arch community is awesome. THANKS! big_smile

I've started reading the first book i mentioned, and it seems to be good. Though it also seems there will be a few days before i actually code anything in C, as I apparently need to know all the underlying concepts and the LC-2 language. I wanna have a good grasp around this language, so I guess that's a good thing smile

Again, thank you guys! big_smile

Offline

#22 2010-07-12 17:38:07

PJ
Member
From: Sweden
Registered: 2005-10-11
Posts: 602

Re: Learning C, but cant get started without..

Another thing you could do is to add -g to all of the arguments for gcc. If you do that you could step through the code and see how things changes for each step or run to a certain brekpoint in the code. It is possible to debug with only gdb but it is so much easier with a frontend and my personal favorite so far is kdbg.

gcc -g -Wall -Wextra -std=c99 -pedantic -o run_me code.c
kdbg run_me

Offline

#23 2010-07-12 22:15:00

xamaco
Member
From: Corsica, France
Registered: 2010-04-05
Posts: 87

Re: Learning C, but cant get started without..

Personally, I use vim, but I got to play along with gedit, and it's quite nice. If you use it, I would suggest you to install gedit-plugins.
Otherwise, the K&R is a fantastic book. Certainly not for a beginner. Sure, I read it at the right time, but as a programmer, it's really the book wich did bring me the most benefits. It's all thumbed down, and currently I'm re-re-reading the last chapter, No VIII: 'The UNIX System Interface'. The code is so elegant and light, pure beauty. C has its defects, I learned a fair amout of other languages, but never another language has seemed to me as elegant as C, WHEN it's well written. And I suspect it's all due to this bad old book smile.
[edit]As regard to elegance, you have to consider that C is a low level language. Very close to the metal. If you know well, C, your compiler, your CPU, you can almost guess which binary code your compiler is going to create.[/edit]

Last edited by xamaco (2010-07-12 22:24:12)

Offline

#24 2010-07-12 22:24:09

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: Learning C, but cant get started without..

PJ wrote:

Another thing you could do is to add -g to all of the arguments for gcc. If you do that you could step through the code and see how things changes for each step or run to a certain brekpoint in the code. It is possible to debug with only gdb but it is so much easier with a frontend and my personal favorite so far is kdbg.

I was going to try out kdbg because of your comment, but I noticed it uses Qt 3. Do you find that to be a problem? (I guess I don't know why it would be) tongue Do you know if there are plans to convert it to Qt 4? Have you tried other gdb frontends?

EDIT: (I agree with stqn, I didn't mean to imply that you need a debugger when you are just getting started with programming)

Last edited by drcouzelis (2010-07-12 23:34:02)

Offline

#25 2010-07-12 22:53:21

stqn
Member
Registered: 2010-03-19
Posts: 1,191
Website

Re: Learning C, but cant get started without..

I don't think a debugger will be needed as long as alf is learning the language...

I think that for the books examples, a simple text editor and a terminal will be enough. An IDE is nice to have for relatively big projects with many source files, but it's more complicated than the command line for very small projects.

Syntax colouring and "smart" automatic indentation are also not that useful IMO.

Offline

Board footer

Powered by FluxBB