Learning C

Started by Shadow, February 11, 2009, 05:47:53 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Shadow

I have to teach myself C for a summer research job. I got "The C Programming Language" by Kernigan and Ritchie on the reccomendation of the prof I will be working for, but it is a little bit dated. [haties] the whole language is dated, beats me why they don't use C++. Anyway, do any of the more experienced programmers have any tips for me on how to go about learning it?

Basically, most of the code I will be working with will be already written, it's a matter of being able to read, understand, and modify existing code to fit into the context of my research project. So I won't be doing anything from scratch, but the programs will probably be quite involved mathematically. Is there a current standard math library I should familiarize myself with?

I have NetBeans IDE at the moment and I am slowly puzzling out how to use the darn thing.
<=holbs-.. ..-holbs=> <=holbs-..

bjornredtail

Mathematics research? Are you sure you want to be using C? C is very good at a lot of stuff. It is good if you need code to run fast, or if you are writing an OS or something else that has to talk directly to hardware. It's decant for scaring freshman computer science students. It's not particularly easy to use properly (why it is actually a good first language to learn, if you have proper instruction.) As my Systems Programming Professor said, "If you need write fast code, write in C. If you need to write code fast choose something else"

I'll assume you at least understand control flow and stuff like that...
-C is a bit hard to deal with without at least some knowledge of what is going on underneath. If you can, take a class in assembly or one dealing with computer architecture. A lot of the stuff that happens in C makes a whole lot more sense afterwords.
-Learn ur pointers. Learn ur malloc. You will be using pointer arithmetic at least occasionally, and possibly quite a bit more often.
-Learn at least the basics of a debugger. Being able to find out exactly what caused that segfault will save you a /lot/ of trouble.
-I'd ditch the IDE and just use vim and make and the command line. I'm also a complete unix nerd who has a tinge of nostalgia for an era I never got to experience, thus I actually like the command line and stuff. So, I wouldn't necessarily recommend that you do the same.
-C++ is a beast compared to the simple and beautiful C. I'll admit right now that I simply just didn't understand much of it last I dealt with it (I actually wrote a decant chunk of a rudimentary processor simulator.) And, I do understand Object Orientation. So, I really can't give much advice on transitioning from C++ to C.
-A math library? There is the regular libmath, which is pretty standard. Um... Are you doing anything particularly fancy mathmaticly speaking?

(on a side note, I like C, the K&R and the Unix command line largely because they are 'dated' (well, not really 'dated'). Quite frankly, I think a lot of software was built better back then, before we had university departments dedicated to "software engineering". Though, to be fair, there wasn't nearly as much software back then either)
0==={=B=J=O=R=N=R=E=D=T=A=I=L==>
AKA, Nevadacow
First person to ever play RWL

"Program testing can be used to show the presence of bugs, but never to show their absence!"-Edsger W. Dijkstra

Visit http://frostnflame.org today!

The Lady Shael

~The Lady Shael Varonne the Benevolent of the Southern Islands, First Empress of Mossflower Country, and Commandress of the Daughters of Delor

RWLers, your wish is my command...as long as it complies with the rules.


Shadow

#3
It's physics research, so I assume I will have to write code to translate massive data dumps from simulations into something useful and physically meaningful. The math will probably be vectors in 3D and other things related to optics. It doesn't matter how good C is for these things, it's what the lab uses, so I have to as well.

I prefer procedural languages to object oriented, although that might be just because I don't have much experience with objects. And I don't know enough about linux or vim to use that effectively for coding. I can get around, but only the basics.
<=holbs-.. ..-holbs=> <=holbs-..

windhound

If you want a good, simple linux gui text editor I <3 Kate
I used Eclipse when doing my 3 semesters of Java and it was nice to have.  Java's error checking is rather bad, it kinda guesses around the point where the error occurs and says "hey, there's a problem in this area, fix it!"  Eclipse pointed out the exact error and usually gave hints on how to fix it.  It also kept file management sane.  An IDE is nice to have
http://www.eclipse.org/cdt/

You have your Terminal in Green and Black dontcha Nev?  I do!
A Goldfish has an attention span of 3 seconds...  so do I
~ In the beginning there was nothing, which exploded ~
There are only 10 types of people in the world: Those who understand binary, and those who don't

bjornredtail

#5
I did, but it proved to be /less/ legible than default, so I switched it back.

Ultimately it comes down to reading and writing a good chunk of code. Give at least some of the programs in the K&R a try. I assume you have the 1988 second edition, not the 1976 first edition. There have been /some/ changes to the language since '88 and quite a few since ~'72 when it first came into any use.

Oh, and if you are on Linux, be sure to install the developer manpages. They are the single best reference for library.
0==={=B=J=O=R=N=R=E=D=T=A=I=L==>
AKA, Nevadacow
First person to ever play RWL

"Program testing can be used to show the presence of bugs, but never to show their absence!"-Edsger W. Dijkstra

Visit http://frostnflame.org today!

Shadow

I use mainly XP, but I have Ubuntu installed in a VM on my computer, so I can use that as needed. I stayed away from Eclipse on the advice of my Dad. He said it was an excellent IDE but I would spend more tim learning Eclipse than learning C ^_^
<=holbs-.. ..-holbs=> <=holbs-..

windhound

That's fair enough advice
Eclipse has a steep learning curve for Java  Not played its C implementation but I'd assume its similar in steepness.  Useful as can be once you get rollin' though

I think you have your VM structure reversed though...  Should have the stable, virus free OS as a base and the more vulnerable OS in the VM =D
A Goldfish has an attention span of 3 seconds...  so do I
~ In the beginning there was nothing, which exploded ~
There are only 10 types of people in the world: Those who understand binary, and those who don't

Shadow

I am not quite good enough with linux yet to use it as a main machine, and I strongly doubt that the university files I get to do my work would be linux compatible. I know a lot of people in my intro comp sci class has difficulties with that. Maybe after the summer.

Out of curiosity, am I right in saying that most of the linux OS is written in C? I seem to recall somone saying that.
<=holbs-.. ..-holbs=> <=holbs-..

bjornredtail

That is true of most of nearly all modern operating systems. It is the right tool for the job. It can do things like talk directly to hardware, and twiddle with bits, which is the bread and butter of what operating systems do. It is fast, so that the OS isn't usually the bottleneck. Plus, it's relatively portable, and when it isn't it makes it easier to bundle the stuff that isn't portable together.

As far as IDEs go, you might consider Jrgasp, Anjuta and Bloodshed. All of them are far simpler than netbeans, eclipse or many other 'professional' ides.
0==={=B=J=O=R=N=R=E=D=T=A=I=L==>
AKA, Nevadacow
First person to ever play RWL

"Program testing can be used to show the presence of bugs, but never to show their absence!"-Edsger W. Dijkstra

Visit http://frostnflame.org today!

Shadow

Alright I'll check them out. So far what I have been learning from C is more or less the same stuff as java minus objects and classes, and is actually more intuitive for me (so far). I'm sure I'll run into some fun stuff when i ge to pointers and the like. I have as yet had no reason to mess around with the bits of anything, so that part seems a bit confusing to me at the moment, but I doub't I'll be required to do very much of that in my project.
<=holbs-.. ..-holbs=> <=holbs-..

windhound

I was mostly joking about the OS thing, use what you're most comfortable with. 
I learned Java while teaching myself Fedora (Core 4), fun times. 

Out of curiosity though, where do you see compatibility failing?
NCSU has Redhat on campus (w00t) and as a whole the campus is very cross-platform friendly.  I've seen more Macs in my ECE classes than anything else lately, which is kinda surprising.  Spotted an Ibex background (Ubuntu) in class just today as well.
The only failing I've had is actually just recently, I'm taking an English class online this semester (missed the signup date, oncampus classes filled up, gotta have it to graduate) and when reviewing a classmate's paper (.doc) some of the formatting was off in openoffice.org.  My G3 iMac has Office 2004 on it so it wasnt a problem for me, but yeah. 
As far as submitting assignments all my professors accept pdfs, which openoffice.org does very well.  It saves .doc too, but when formatting is a part of your grade its better to be safe than sorry.
A Goldfish has an attention span of 3 seconds...  so do I
~ In the beginning there was nothing, which exploded ~
There are only 10 types of people in the world: Those who understand binary, and those who don't

Shadow

All I have is stories from classmates who are unable to open the files we are given in the assignments. Better safe then sorry as you say. OpenOffice wasn't really doing it for me either - it was having a lot of trouble handling the word and spreadsheet files from the university. Probably something I could easily fix but lack the expertise to do.
<=holbs-.. ..-holbs=> <=holbs-..

Blobfish

Guerilla strike, team 1, move. Leave no survivors, extreme prejudice! KILL THESE SPAMMING SCUM!!!!!
Worship the mighty Blobfish

Quote from: Blobfish on May 01, 2011, 12:04:37 PM
Economic Left/Right: 3.12
Social Libertarian/Authoritarian: 7.59

Rights are for the weak.