OK, now that we're done with that awful play on words(letter?), let me get straight to the point:
I want to learn to code in C! I have downloaded and installed Xcode on mac(it wouldn't complete though, what is that about? It said 2 minutes remaining for 12 hours, so I just turned the computer off, and when I started it again it was installed).
What I'm looking for is to get a better overview over the whole process(why the files and folders are where they are in a project), as well as just learning to code.
Honestly, you're probably best off learning C#, learning a .Net language actually has some real world applications and can allow you to program software for anyone on an MS Windows platform. Microsoft has made it clear that's the direction they want to go with .Net, and the more complicated aspects of C++ such as writing to specific memory bits has been removed. MSDN has some really good tutorials and has a number of chapters of some good books on learning .Net languages for free.
If you're not interested in .Net, I would say 100% you should look to learn Java (not actually all that different from C++), that would actually be useful for programming apps and cross-platform software.
Learning C++ is pretty hard, but also very rewarding. You can also easily transfer your knowledge to other languages, once you've mastered the "first levels". If you're entirely inexperienced with programming, I'd suggest that you might try one of the "easier" languages first (such as C#), because the sheer power of C++ is pretty intimidating sometimes.
Don't learn C, though, unless you're planning to study software engineering. C is used to design operating systems and other software that's "close to the hardware". (don't know how to put this in english sry)
On April 24 2012 00:52 virpi wrote: If you're entirely inexperienced with programming, I'd suggest that you might try one of the "easier" languages first (such as C#), because the sheer power of C++ is pretty intimidating sometimes.
Actually Visual Basic is probably one of the easiest languages to learn. I'm no CS major, and despite my short attention span even I was able to learn enough VB to make some simple desktop applications. It has some real world applications too, such as being able to write macros in MS Office. Plus many of the concepts transfer pretty easily to other .Net languages like C#.
I started learning c++ a year ago as my first programming language. Everything is going allright and I never found it intimidating or anything. IF you jsut start at the basics and slowly work your way upwards then it is doable.
I went to that codeacademy site, kinda dumb. Just grab a programming book for noobs or google cprogramming and start coding. Don't know why you would want to learn old C first, but hey that's your choice. Even if you wanted to learn COBOL I wouldn't stop you. use google and your success is determined by your motivation and self-discipline. Good luck.
If you have your heart set on C then my advice would be to grab a solid book on learning C for beginners and work through it from start to finish. C is closer to the metal than many languages and there is a lot of knowledge you'll need that can't be gleaned *easily* from reverse engineering existing programs such as memory management, memory structure layout, pointers, etc A good book will be able to introduce and explain in a way that you'll be able to pick it up more quickly.
Finding someone with a lot of experience in C that you can ask questions of would also be a big help.
You definately want to learn C first (the book I link actually teaches you a simple RISC assembly, which I think is the best way to learn C), especially if you're just doing this as a hobby. While you won't be a productive as you would be learning a high-level language you'll understand a whole lot more.
The intro to programming class at my school used this
and I highly recommend it. It's particularly useful if you're interested in learning programming just for fun, as it will teach you what's actually going on inside your computer.
Additionally, I would recommend learning to use a proper editor (I use emacs, but vim is fine too), make, gcc, and the command line. When you're learning how to program an IDE (like Xcode) can actually complicate things as it will hide a lot of what's going on. Learning to use a Unix-like operating system (I use Gentoo, a Linux distribution) is also a huge plus, but as your on Mac OS X you'll be alright (there's some Unix in OSX if you look hard enough ).
I friggin bought an entire book to learn C. Only to learn that I have no talent whatsoever to do learn it, took me weeks just to learn how compile my simple lines of code.
Don't start with C. It'll teach you the wrong stuff. You're better off learning something else that's actually useful. C actually will hinder your learning later on.
Rather than learning C or C++, how come you guys haven't suggest to just learn Java? I read that it's similar to C++ but better and more convenient. Correct if I'm wrong because I'm trying to learn too.
EDIT: just noticed that someone mentioned Java, can anyone further elaborate on it?
On April 24 2012 02:01 Snuggles wrote: I friggin bought an entire book to learn C. Only to learn that I have no talent whatsoever to do learn it, took me weeks just to learn how compile my simple lines of code.
There's no such thing as "no talent to learn it". You might not have genius skills to hack google at 15, but to learn how to code and eventually get senior dev position - anyone can achieve that. Literally, anyone.
I agree that anyone can do it, but there is definitely talent or a particular way of thinking that makes progress much faster for learning how to code.
From my experience, Java or C# is probably easier to pick up and is good for teaching abstraction, etc. C requires a little more bookkeeping from the programmer in terms of memory management/pointers, but can be written to run faster than Java. C++ is extremely powerful but quite a bit different than the other languages to learn -- what is properly written code in C will often work on C++, but will almost inevitably be a suboptimal implementation in C++.
Of course, the language you should start with depends on what you want to do with it...
Nobody has mentioned it yet, but I'll even put in a vote for learning Objective-C if you happen to be on a Mac. Working with Objective-C and Cocoa is actually really nice and you can go from learning to making a real desktop/iOS application pretty quickly. Objective-C still lets you learn about object oriented programming, and you can also make use of C structures (and c++ but I would steer away from that if you're just learning) easily.
It might not be as valuable for employment, unless you're looking into iOS or Mac development. But once you've learned one language it's really not difficult to pick up more in the future.
On April 24 2012 02:48 fire_brand wrote: Don't start with C. It'll teach you the wrong stuff. You're better off learning something else that's actually useful. C actually will hinder your learning later on.
Learning C will not teach you the "wrong stuff", whatever that is, and C is definitely useful.
Visual basic and C# are both quite nice to learn. Knowing the basic functions and capabilitys of c/c++ would give you a good idea of what kind of things you can do. Don't go to deeply into C though. Once you know the basic building blocks move on to C# or VB. The forms, threading, lists will make you never want to go back.
On April 24 2012 02:48 fire_brand wrote: Don't start with C. It'll teach you the wrong stuff. You're better off learning something else that's actually useful. C actually will hinder your learning later on.
Learning C will not teach you the "wrong stuff", whatever that is, and C is definitely useful.
From what I read when I was teaching myself programming most people agreed that learning C first would give you bad habbits that will cause many problems in c+ and what not.
On April 23 2012 23:22 TheToast wrote: 1. Honestly, you're probably best off learning C#,
2. Java (not actually all that different from C++), that would actually be useful for programming apps and cross-platform software.
What is this, I don't even??!
C and C++ don't have any ACTUAL applications nowadays? A quick look here :http://www.thewindowsclub.com/what-is-android-operating-system-a-beginners-read
A beginners read on this article shows that: `Android OS consists of over 12 million lines of code written in C / C++ / Java and XML.`
`Java is not that different from C++`
Have you ever seen Java code and have you ever seen C# code. That is right, they look alike
Hello world in C#:
class Hello { static public void Main() { System.Console.WriteLine("Hello World"); } }
Hello world in Java:
class Hello { public static void main(String[]args) { Systen.out.println("Hello World"); } }
You better go to school, kids, cause if you don't you will end up saying in forums that Java is (not that different from C++, actually). Shame on you for being outright stupid.
So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here.
I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate!
On April 23 2012 23:22 TheToast wrote: 1. Honestly, you're probably best off learning C#,
2. Java (not actually all that different from C++), that would actually be useful for programming apps and cross-platform software.
What is this, I don't even??!
C and C++ don't have any ACTUAL applications nowadays?
Okay, you're just putting words in my mouth. I never said C++ didn't have applications. I was implying that C didn't have that many real world applications in terms of development of desktop applications. You do know he was talking about C and not C++ right?
You better go to school, kids, cause if you don't you will end up saying in forums that Java is (not that different from C++, actually). Shame on you for being outright stupid.
They're both object oriented programming languages, just because the syntax isn't the same doesn't mean they are drastically different. And if you want to discuss this further, try it without the attitude maybe?
On April 23 2012 23:22 TheToast wrote: 1. Honestly, you're probably best off learning C#,
2. Java (not actually all that different from C++), that would actually be useful for programming apps and cross-platform software.
What is this, I don't even??!
C and C++ don't have any ACTUAL applications nowadays?
Okay, you're just putting words in my mouth. I never said C++ didn't have applications. I was implying that C didn't have that many real world applications in terms of development of desktop applications. You do know he was talking about C and not C++ right?
You better go to school, kids, cause if you don't you will end up saying in forums that Java is (not that different from C++, actually). Shame on you for being outright stupid.
They're both object oriented programming languages, just because the syntax isn't the same doesn't mean they are drastically different. And if you want to discuss this further, try it without the attitude maybe?
C++ is a OO language and java is also. Nice similarity. It's like saying an elephant is similar to a fish since they both are animals.
C# is far closer as idea and syntax and level of abstraction to Java than C++ is to any of them.
Well I don't recommend java first if you want to learn programming more seriously in the future. It's a badly designed language, in my opinion. Though for sure it has libraries for everything.
On April 24 2012 06:20 TheToast wrote: I was implying that C didn't have that many real world applications in terms of development of desktop applications. You do know he was talking about C and not C++ right?
[Java and C++ are] both object oriented programming languages, just because the syntax isn't the same doesn't mean they are drastically different. And if you want to discuss this further, try it without the attitude maybe?
As far as I'm aware, plain C is still used for a lot of high performance computing applications. Desktop applications or web services? Yeah, go with C# or Java. But C's still around to stay.
Also, Bjarne Stroustrup (the original creator of C++) would disagree with your characterization of C++ as an object-oriented programming language. C++ supports object-oriented programming, but is also capable of much more. I had a pretty easy time learning Java after C, but learning proper C++ was an entirely different beast.
On April 23 2012 23:22 TheToast wrote: 1. Honestly, you're probably best off learning C#,
2. Java (not actually all that different from C++), that would actually be useful for programming apps and cross-platform software.
What is this, I don't even??!
C and C++ don't have any ACTUAL applications nowadays? A quick look here :http://www.thewindowsclub.com/what-is-android-operating-system-a-beginners-read
A beginners read on this article shows that: `Android OS consists of over 12 million lines of code written in C / C++ / Java and XML.`
`Java is not that different from C++`
Have you ever seen Java code and have you ever seen C# code. That is right, they look alike
You better go to school, kids, cause if you don't you will end up saying in forums that Java is (not that different from C++, actually). Shame on you for being outright stupid.
Have you seen it in ruby?
print "Hello World"
What are your goals? Choosing a language for learning is pretty important as it will shape your thinking process. I would reccomend choosing a language which is commonly used in areas you wish you utilize. For an all purpose language, I would say java is the way to go. If you want to do video games, go with c/c++/c#. If you want to do web stuff, php and ruby are the right choice.
Learning C as your first language might be more difficult than Java for example, mainly (at least for me) because you have to manage memory yourself and the use of pointers. If you have no programming experience, you might want to start with Java (in netbeans or something) then go to C. Alternatively, you could just jump right in C and deal with a slightly steeper learning curve.
Learning C is great if you ever want to do low-level stuff like writing an OS or doing any embedded programming / compiler stuff because it offers a lot of flexibility in manual memory management that can allow you to write some really efficient code. Some people aren't interested in that stuff with the web-craze nowadays brought on by google, facebook, twitter etc but that just means that there will be fewer people with that kind of skill. Don't turn away from C just because its an older language that appears to have fewer options in the real-world, it's a good place to start and will let you appreciate other languages that much more later on. It really depends on your motivation for programming and what you want to create.
The Big Nerd Ranch guide will not teach you all of C, but the basics to get started before you start diving in to Objective C (Apple's prefered language for development). The book is very good for people who want to learn on their own pace, and prefer a more practical approach. For example, the book won't teach you every detail of vodoo black magic needed to master pointers and memory management, but just what you meed to understand and work with references in Objective C.
You can then proceed with the Cocoa (Apple's development libraries) books, that introduce you more into OSX and/or iOS programming.
Also, a very good motivator is to have a project you want to work on. Doesn't need to be very sophisticated, just something you can find useful and cook.
Personally I really appreciate programs that are small, but with a lot of attention to detail
I've known java for a while, and I had a homework assignment given to me which was to write a quine in C. C really isn't that different from Java (besides the obvious difference of allocating memory through pointers and the different syntax, C being lower level, etc). Honestly, once you learn one language, picking up the rest of them is easy, as the stuff you build, and the skills you learn from 1 language give you a foundation for learning the others. So my advice is to start with java (what I did) but honestly if your heart is set on C, then go for it!
I'm a relatively new programming student just like you. I have minimal experience in C. However, I do have a lot of experience in C++ and am teaching myself Ruby right now. I don't think that there is any single best language to start with as you must learn to program before you learn any language in depth. That being said if you have Skype I think that I could help you out tremendously by just walking you through some basics and answering any questions you might have. You might even be able to help me with a cute little rocket ship game that I am working on.
If you (or anyone else) is interested or has any questions I have a fair amount of free time so send me a message on TL and I can send you my Skype info (not posting here).
On April 24 2012 06:11 olabaz wrote: So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here.
I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate!
I was one of the better programmers when I did my MSc in particle physics, not that I could have a valid opinion...
C will not help you in physics, it will probably just hinder you, but you've obviously been told this and think you know better. Most physicists stuck with FORTRAN for the most part, they're switching over to C++ with a lot of the larger collaborations (event generators etc) because OO is too useful.
If you're serious about physics over programming you'll not need to go in depth with anything, just learn Java then C++ and some scripting languages, as well as how to use Unix and you'll be fine, you'll learn what you need when you need. As people have said, C is for low level things, learning it will serve no purpose in the physics world and you'll simply have to erase bad habits when you learn a more appropriate language.
On April 24 2012 02:48 fire_brand wrote: Don't start with C. It'll teach you the wrong stuff. You're better off learning something else that's actually useful. C actually will hinder your learning later on.
Learning C will not teach you the "wrong stuff", whatever that is, and C is definitely useful.
From what I read when I was teaching myself programming most people agreed that learning C first would give you bad habbits that will cause many problems in c+ and what not.
I'm a senior CS undergraduate student and I honestly wish that my University picked C or C++ as its main language instead of java. While java might be an easy language to pick up, I feel extremely gimped in regards to understanding dynamic memory management and trash collection. I am pretty fluent and Java and learning C++/C right now so I can actually get a job because there seems to be little demand for Java programmers in all the jobs that I have applied for so far. If anything learning Java first over C has taught me more bad habits than I think learning C would have. A good book to start with is http://www.amazon.com/Programming-Modern-Approach-2nd-Edition/dp/0393979504?tag=tealiq-20 This is the one I am using to guide my own studies.
As for differences, I think the most defining ones are C++ is basically C with object orientation and a ton more tools to make your life easier Java and C# are really similar in that they run with virtual machines and they are super high level languages that have a lot of automation and built in safety.
I think the most common starting language is either C++ or Java. I think C++ is better to start with. The basic syntax is far easier to understand. Take a C++ hello world:
#include <iostream> using namespace std; int main() { cout << "Hello, World!"; return 0; }
compared to a Java Hello, World:
public class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World!"); } }
In C++, you don't have to think about what public, static, void, or class mean. The other major part about C++ is pointers. Everyone should play with pointers and understand how they work. In Java, every object works essentially as a pointer. Java is an easier language to program in once you are familiar with programming, but C++ is easier to start and better for learning.
No idea how old you are, but I guarantee if you go get some advanced certificates in Java programming you're going to get hired very fast in America. There's so many java programming jobs right now. I understand it decently but I just don't like programming enough to do it day-in and day-out. If you can stand it you could be making 80$/hour....
I learned C as my first programming language and I can recommend to anyone to do it as well. It will give a solid foundation for learning other languages and well as forcing you to learn some computer concepts along the way. There are plenty of applications of C, like Linux programming, embedded devices, etc. It will also be straightforward to learn C++ from there.
If you get a chance get K&R book either as your main book or as a companion to whatever book you are reading. It's a classic.
On April 24 2012 06:11 olabaz wrote: So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here.
I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate!
I was one of the better programmers when I did my MSc in particle physics, not that I could have a valid opinion...
C will not help you in physics, it will probably just hinder you, but you've obviously been told this and think you know better. Most physicists stuck with FORTRAN for the most part, they're switching over to C++ with a lot of the larger collaborations (event generators etc) because OO is too useful.
If you're serious about physics over programming you'll not need to go in depth with anything, just learn Java then C++ and some scripting languages, as well as how to use Unix and you'll be fine, you'll learn what you need when you need. As people have said, C is for low level things, learning it will serve no purpose in the physics world and you'll simply have to erase bad habits when you learn a more appropriate language.
On April 24 2012 06:11 olabaz wrote: So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here.
I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate!
I was one of the better programmers when I did my MSc in particle physics, not that I could have a valid opinion...
C will not help you in physics, it will probably just hinder you, but you've obviously been told this and think you know better. Most physicists stuck with FORTRAN for the most part, they're switching over to C++ with a lot of the larger collaborations (event generators etc) because OO is too useful.
If you're serious about physics over programming you'll not need to go in depth with anything, just learn Java then C++ and some scripting languages, as well as how to use Unix and you'll be fine, you'll learn what you need when you need. As people have said, C is for low level things, learning it will serve no purpose in the physics world and you'll simply have to erase bad habits when you learn a more appropriate language.
C is not useless for physics...
C is the backbone language for SO many other languages and is still used for MANY applications and systems.
On April 26 2012 07:06 darthcaesar wrote: I think the most common starting language is either C++ or Java. I think C++ is better to start with. The basic syntax is far easier to understand. Take a C++ hello world:
#include <iostream> using namespace std; int main() { cout << "Hello, World!"; return 0; }
compared to a Java Hello, World:
public class HelloWorld { public static void main(String args[]) { System.out.println("Hello, World!"); } }
In C++, you don't have to think about what public, static, void, or class mean. The other major part about C++ is pointers. Everyone should play with pointers and understand how they work. In Java, every object works essentially as a pointer. Java is an easier language to program in once you are familiar with programming, but C++ is easier to start and better for learning.
This is complete and utter bullshit. C++ is far more complicated, feature rich and requires annoying memory and pointer management. It does not force you to use a certain style (object oriented, like java) and is generally probably the most beginner unfriendly language you could find (of the major ones, stuff like lisp and caml not included). Pointers are a bad argument, modern languages stray away from them, because they are a major source of errors.
No, I'm not bashing on C++ as a language in general, I just think that it's not suited for beginners. When you start out, you want to write programs that work, not fight with compilers, linkers, memory leaks, buffer overflows, header files etc. I would recommend java, although not because of the language itself, but because the library and the IDE eclipse, which are very easy to use and learn with - plus there is a lot of material and the language is used widely. You can do pretty much everything in Java with the standard library.
I understand that you want to learn C, but I would really not recommend it. It does teach you a lot about hardware, memory management etc., but it does not teach you how to be a good programmer. To put it into an RTS anology:
Java is SC2 C++ would probably be Brood War C is Dune2
Dunno why there's so little support for python or ruby. In terms of just learning to think the right way, those are probably the best bet. Very little getting between you and making stuff happen. Plus, interactive interpreter is great for experimenting and discovering new ideas. I personally don't really like ruby, but expect it's just because I'm not cool enough to "get" it. Several programmers I respect technically really like it.
I'd be interested to hear more about C/C++ teaching bad habits. I write C daily, and have worked with java, C++, perl (gak), and python codebases professionally. My first language happens to have been C++. I've found that most if not all "bad habits" arise from ignorance and poor instruction, and aren't really the sort of thing that a language forces on you.
If you're just learning to program, and particularly if you want to learn C, I highly recommend finding someone(s) that's willing to look over your code. Some things don't really communicate well in books and benefit greatly from having experience looking over your shoulder.
I really hate that Ruby forces no types. I find the lack of type fixing very useful at times, but at others it's extremely detrimental. My game is coming along quite nicely, and it is purely done in Ruby. (lol Ruby game)
It's really quite incredible how the OP clearly isn't showing an interest in any other languages and yet you guys keep rambling on about this language is better than that - blah blah blah.
Arnstein, C is a wonderful language. It is mainly used for systems programming, so it is a very low level language. Fortunately, it's a no-bullshit language, meaning code is usually very direct and easy to follow. C is not an object-oriented language, so you will not run into things like "classes" or "inheritence", which can sometimes lead to some very ugly and confusing code.
I will explain the difference between some higher level languages and C, and you could use that to decide where you would like to start, if your heart is not already set on C. This should give you a good perspective on what you will be embarking on. Most really high level languages have these:
Objects and object-oriented programming languages were something designed to make human design of programs simpler. The entire idea behind an Object is that you group similar properties and functions of a "real-life" object into one cute name.
Here's an example to give you a better idea. Suppose you were designing a video game and inside that video game there are tanks. We can even take the Seige Tank is starcraft as a concrete example. If were to think about the important PROPERTIES of a tank we could make a short list, something like this:
- Armor - Damage - Health - Speed
And if we were to think of some important functions or actions of a tank we could come up with something like this:
- Attack - Seige Mode - Stop - Move
Now I can create an "object" that groups all these properties together to make it easy for myself. I could say:
myTank.Armor = 3; <- This would change the armor value of the tank to 3 myTank.Damage = 10000; <- Holy crap that's STRONG!!!
C lacks the ability to create objects directly. However, in can still be done pretty similarly to most high-level langauages through the use of structures. You will learn about those eventually.
Garbage Collection/ Automated Memory Management + Show Spoiler +
As you may imagine, inside your program you will be creating a bunch of variables, objects, strings, and all sorts of stuff. Well, who is keeping track of all that stuff? When should stuff be destroyed and when should it be kept?
The answer to this question depends on what language you are programming in. Most really high level languages like java, C# and many others have what is called Garbage Collection and Automated Memory Management.
Garbage Collection and automated memory management is exactly what it sounds like. Your program will cycle through all the stuff you've made and delete things that it thinks you will no longer ever use. Most of the time this works pretty well, meaning you can program-and-go and not have to think about problems with memory space running out or using something you shouldn't be using.
C does not gave garbage collection. You will be doing everything manually, so you must keep track of all variables, pointers, and memory that you use. This may sound daunting, and sometimes it can be, but unless you're solo making software to manage an entire airplane that spans over a million lines of code it probably would not bother you too much.
Pointers? What the hell is a pointer, anyway? A pointer is exactly what it sounds like. It's a VARIABLE that points to something. More technically, pointers point to addresses of memory inside a computer. Snooze. Sounds simple, right?
Apparently it's not. Pointers can be too compliated for some programmers, which is why languages like java and C# have allegidly gotten rid of them. I say allegidly because pointers are such a fundamental part of modern day computers that there really is so escpating them. Really high level languages like java HIDE all the pointer operations going on the background to make programming more trivial.
C does not. You will be dealing with pointers DIRECTLY, and often times even things you think are simple library functions will use pointers. To give a crude example, say you wanted to copy a string. Well. cplusplus.com has a great resource that lays out the common C libraries very nicely for you. You will be using these libraries very often, so keep this link handy! Link is: http://www.cplusplus.com/reference/clibrary/
Let's take a look at strcpy() (Short for String Copy) Link is: http://www.cplusplus.com/reference/clibrary/cstring/strcpy/ " char * strcpy ( char * destination, const char * source ) " This part is the meat of the function. Almost every time you see an ASTERISK (*) in a program in C, it's a pointer. So this function takes in two pointers and even returns a pointer! Just to copy a string!!
The truth about the matter is that pointers require getting used to, but living without them is impossible. They are wonderful and really amazing tools in a programming language.
I realize this probably doesn't matter for you, but higher level languages are generally more secure. That's because majority of low level control is hidden from you. You must realize that your program will be grossly insecure in C. So if you plan on writing an FTP server where people will be submitting personal information, I'd look into learning about how to program securely.
A quick word about C++. The thing that makes C++ interesting is that it's not really a very low level language nor is it a very high level language. C++ is object oriented, however, it doesn't not have memory management and still has pointers. It's really an "in-the-middle" programming language.
C is a great choice for a first programming language, especially if you're a computer scientist. Seems like your degree will be quite technical, so you might be dealing with low level issues and programming a lot. Might as well learn C. And the beautiful thing about C is that it transitions into other languages perfectly. I wrote a post in the "Big Programming Thread" elaborating on this that got updated to the OP. Feel free to check it out. http://www.teamliquid.net/forum/viewmessage.php?topic_id=134491
Let's get started on C! I won't be teaching you the "technical" part of programming because there are a million tutorials out there. I will be teaching you the most important part yet least covered and most confusing part. Setting up your compiler and compiling your first program. I'm going to teach you how to do it on WINDOWS, because most people will be using windows and I want this post to be general. Also, because codeblocks is abysmal trash. Same idea on any OS, really. So we have two things we want do.
Installing, compling, and understanding GCC, which is part of the GNU compiler collection, is our main goal here. Here are the steps:
- Get GCC/GNU via an IDE. - Add the /bin directory to your PATH enviornment variable, allowing you access to a command line compiler as well as other programs.
In case you were wondering, the GNU compiler collection is a set compilers for multiple programming languages. GCC, which is probably the most famous C compiler, is part of the GNU compiler collection.
Part 1: Get GCC/GNU via an IDE
The IDE I'm going to be using here is called dev c++. In truth, this is not a very good IDE but it's great because it's simple to install and use. It's small, supports both C and C++, and contains a /bin folder with the entire GNU compiler collection, which we will use in part 2. So let's head over to dev c++'s site and download and install it. Link: http://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++ 4.9.9.2/devcpp-4.9.9.2_setup.exe/download
Installing this is just like installing any program. If you can't figure this part out, you probably shouldn't be trying to program anyway. Once it's install, run it and you will see this.
Go to File > New > Project... This will open a new tab. Make sure you have Console Application Selection, and make sure C Project is selected at the bottom. You can choose to make it the default language as well. Give the project a name and hit OK. Copy and paste this into the big white portion where all the code is.
The four buttons I have boxed in red are really your favorite buttons. Compile, run, Compile and run, and rebuild. Hit the compile and run button, and your program should be up and running! Congradulations, you've compiled and ran your first program!
You can use dev to start programming and expiermenting with stuff. Have fun with it!
Part 2: Add the /bin directory to your PATH enviornment variable Hit the windows key + r. This will open up run. Type in "cmd" and press enter. Welcome to command prompt! Now, if you've ever done something like type "ping google.com", then I'm sure you've wondered what the hell is going on. This is command prompt running the PING program, which happens to be a command line program. GCC is a command line compiler. Dev C++ makes it all dolled up and cute for you, but really it's just running the GCC command line compiler for you with your source code.
What we need to do is add "gcc" and all the accompanying programs to your windows PATH variable so you can call it for any directory. This will let you use the command line compiler to compile anywhere with any options you like, as well use the accompanying programs. This will come in handy because a lot of tutorials use the command line compiler and I don't want you to feel left out.
Check out the "C:\Dev-Cpp\bin" directory. Notice the gcc.exe and all the other wonderful programs? For those of you NOT using dev, head over to google and use it to download the GNU compiler collection. Install and navigate to the /bin folder. Make sure it has gcc and ld inside that directory. Copy the path, as you will be adding it to your PATH variable to call it from anywhere.
To add that entire directory to your PATH environment variable, go to system properties ( shortcut: windows key + pause|break ) Click "Advanced System Settings" and click the "Enviornment Variables" button.
Warning: Do not randomly change stuff in here. You WILL break your computer. Under "system variables" scroll down until you find PATH. Edit it, and at the end append ";C:\Dev-Cpp\bin" The semicolon seperates paths. Mine, overall, looks like this:
Click okay, save, blah blah blah, and reopen command prompt and type "gcc -v". Some of you might need to restart your computer. You should see a bunch of info if it worked.
Now create a file on your desktop and call it main.c. Copy the code from above. Change the command prompt directory to your desktop, and type "gcc -o myfile.exe main.c". Congrats! You've succesfully compiled using the command line compiler. For those of you need help with the command prompt commands: + Show Spoiler +
"cd" changes your directory. Example 1: cd C:\Windows Example 2: cd Desktop
"dir" lists all files in the directory. Example: dir
Use these to navigate to your desktop.
For those of you wondering why this might be useful, it's because you can now use GCC's full potential without IDE restriction. What do i mean? Well... in the same above scenerio, type "gcc -S main.c" and find a file called main.s on your desktop. Gasp! Voodoo magic, what kinda of code is THAT? Blasphemy, says I!
Enjoy. Hope this helps some of you. Feel free to IM/PM me if you ever need any help.
On April 24 2012 06:11 olabaz wrote: So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here.
I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate!
I was one of the better programmers when I did my MSc in particle physics, not that I could have a valid opinion...
C will not help you in physics, it will probably just hinder you, but you've obviously been told this and think you know better. Most physicists stuck with FORTRAN for the most part, they're switching over to C++ with a lot of the larger collaborations (event generators etc) because OO is too useful.
If you're serious about physics over programming you'll not need to go in depth with anything, just learn Java then C++ and some scripting languages, as well as how to use Unix and you'll be fine, you'll learn what you need when you need. As people have said, C is for low level things, learning it will serve no purpose in the physics world and you'll simply have to erase bad habits when you learn a more appropriate language.
C is not useless for physics...
Care to elaborate?
If you want to learn physics, learn physics, don't add complex programming languages on top of that. You'll have a much easier time, and find it easier to apply something like Java to a physics undergrad course.
I'm sure you can find some use for C, but I've never come across a physicist in academia that uses C, it's not the ideal language and most physicists want to do physics, not programme, but if you think you can somehow squeeze 8 extra hours out of each day to double up your discipline then go ahead.
On May 05 2012 18:35 Abductedonut wrote: It's really quite incredible how the OP clearly isn't showing an interest in any other languages and yet you guys keep rambling on about this language is better than that - blah blah blah.
Maybe thats because the OP asked about learning to code in C then went on to ask what the difference between C++ and C# is.
Sorry, but if you don't know that yet you probably shouldn't be diving right into C, its like saying hey the kid wants to learn to ski down black diamond routes, I see no reason why not, it's what he asked for! It's far easier, especially when learning under your own steam to learn more about the different types of languages and start with something easier, which is what people are recommending which also has fun applications.
Especially since a lot of us probably remember wanting to learn a language, in most cases probably C / C++ and not knowing the differences just blindly went into it only to find out it was completely the wrong language to learn at the time.
The only circumstance I would think learning C first would be appropriate would be if you were on a CS course, learning all the other things about computer systems and being taught in a formal manner, otherwise you're just going to make mistakes.
Thanks for so many replies people! You are all good sources of information, and very helpful!
For those wondering why I absolutely wants to learn C: Next year I'm hopefully starting to study technical cybernetics, and the first language I will learn there is C. I want to start now so the first semester won't be THAT tough(even though people say it's the most intense and theoretically hard study after nanotechnology).
I wonder if anyone actually reads OP's posts here? More than once he clearly said he is going to work with cybernetics so it's obvious he is going to need some low-level grip, C is probably the best language one could ask for that.
While it's definately true that C has many areas of application its also true that as a beginner, you'll be spending way too much time worrying about various C quirks rather than PROGRAMMING. Language is but a tool and ultimately it won't matter what you started out with but by choosing beginner friendly language you'll assimilate core programming ideas much faster. If you go with C you'll have to learn about pointers and other shit and generally waste your time. Go learn C when you have some development experience under your belt and you'll save yourself a lot of time.
On May 14 2012 06:15 og8456 wrote: You really should go for C++ and not C, C is really outdated! ^_^
/Just my opinion!
This could not be farther from the truth.
It's from 1970. That alone should probably tell you that it's outdated
Is it still widely used and has its own niches where it is best? Absolutely! Does that make it a good modern programming language? Nope!
C has been updated since then. And saying C is outdated means it's obsolete - it most definitely is not obsolete as it is still widely used today. I feel like I'm just arguing semantics, but dammit C is NOT outdated no matter how old it is!
On May 14 2012 09:12 Anacletus wrote: And saying C is outdated means it's obsolete
I never said it's obsolete, because it isn't. Its concepts and design are outdated. Sure, you can do most of the stuff you do in modern languages, but basically everything is a hack (error codes instead of exceptions, class-like structs with function pointers etc.)
I mean, if you are not programming on low level (be it hardware or the OS) stuff or desperately need that last bit of performance, there really is no need (or incentive) to use C. You could, no question there, but why would you go through all that extra hassle?
On May 14 2012 09:12 Anacletus wrote: And saying C is outdated means it's obsolete
I never said it's obsolete, because it isn't. Its concepts and design are outdated. Sure, you can do most of the stuff you do in modern languages, but basically everything is a hack (error codes instead of exceptions, class-like structs with function pointers etc.)
I mean, if you are not programming on low level (be it hardware or the OS) stuff or desperately need that last bit of performance, there really is no need (or incentive) to use C. You could, no question there, but why would you go through all that extra hassle?
I understand you are a fanboy, but cmon!
I'm more of a C++ fanboy (mmmm dat performance, am I right?). I'm just not going to let you guys get away with spreading misconceptions about C!
This thread makes me sad. The OP comes out knowing what he wants to learn and asking for help learning it, and what does everyone tell him? Their own opinions on what he should learn instead? Come on... there are other perfectly good threads for that.
OP, I see CecilSunkure linked his series of intro-to-C-programming tutorials above, and they're decent.
The original book on C, Kernighan and Ritchie's The C Programming Language is still considered one of the best references on the subject, although I'm not sure of its suitability for a beginner. It's a little expensive but you could probably find it, or parts of it, online if you looked. Of course you do want the second edition, the original is a bit dated but the 2nd ed covers ANSI C which is basically the lowest-common-denominator of what all compilers support these days.
The folks who frequent Freenode's ##c can be a bit off-putting for someone who just wants a simple question answered (and rightly so; they're busy people) but if you have a specific, carefully-worded question to ask they will always have the correct answer (and a citation from the standard to back it up). Their wiki also has some good links to useful resources.
Finally a bit of my opinion to leave a sour taste in your mouth. C is a lot of fun to program in once you've done it for a while and have stopped making the common mistakes. It's unforgiving: you have to be both precise and accurate in what you're telling it to do; if you just sort of fake it (which you can get away with in some languages) you'll find that it actually causes the most frustrating problems.
BTW, you may or may not (I don't know what's installed on Macs by default) already have a great reference for the C standard library installed, in the form of manual pages. When you're not sure what a command or function does, instead of going straight to Google, try opening a terminal and typing 'man command' (without the quotes). As an example, check out the web-based version of the manual page for printf(3).
For beginners, the objective is to learn HOW TO CODE, not how to use whatever language is the favourite this month.
Personally I would start with something that has strong string parsing like PERL or Python as trying to battle compilers while designing algorithm is not fun at all.
With that being said, C is still very influential, Java, C#, Objective C all derived their syntax from C, but seriously though, Syntax and Keywords should be the least of your concern as a programmer.
On April 24 2012 06:11 olabaz wrote: So I also recently decided to learn C and have been learning for a couple of days now. The book recommended by MIT as well as a bunch of other legitimate sources seems to be C Programming Language. I looked into this book and did not really like that they didn't give the main function a return value. I then found out about another book that is widely accepted called C Programming: A Modern Approach and I really like the way it is written and laid out so far, and it is what I'll be using. A larger list of books can be found here.
I was told by a lot of people not to learn C but I feel like it'll be a fun exciting language that will help me in the my future studies of physics. Haters gonna hate!
I was one of the better programmers when I did my MSc in particle physics, not that I could have a valid opinion...
C will not help you in physics, it will probably just hinder you, but you've obviously been told this and think you know better. Most physicists stuck with FORTRAN for the most part, they're switching over to C++ with a lot of the larger collaborations (event generators etc) because OO is too useful.
If you're serious about physics over programming you'll not need to go in depth with anything, just learn Java then C++ and some scripting languages, as well as how to use Unix and you'll be fine, you'll learn what you need when you need. As people have said, C is for low level things, learning it will serve no purpose in the physics world and you'll simply have to erase bad habits when you learn a more appropriate language.
C is not useless for physics...
Care to elaborate?
If you want to learn physics, learn physics, don't add complex programming languages on top of that. You'll have a much easier time, and find it easier to apply something like Java to a physics undergrad course.
I'm sure you can find some use for C, but I've never come across a physicist in academia that uses C, it's not the ideal language and most physicists want to do physics, not programme, but if you think you can somehow squeeze 8 extra hours out of each day to double up your discipline then go ahead.
Why not just do a Computer Science degree?
Don't say I didn't warn you.
I agree that C isn't required to learn physics and neither is programming but, isn't that obvious? They're different fields but that doesn't mean they're mutually exclusive. Many of today's popular programs used for numerical computations were written in C like MATLAB, Mathematica, and Maple. Now sure you can learn to "program" in those but that code doesn't carry over to other languages and of course they're not as powerful until they're combined with C or another similar language.
I think it's a good idea to learn C. C is the rolemodel for most programming and C++, C#, objective-C and even Python are all derived from C since it's such a common language, if you know C, you should feel at home in most languages since constructs, key words etc were often taken from C.
Problem though, C is not all that useful anymore. If you want to code something very heavy, you'll probably use C++ instead since C++ is a superset of C, it does everything C does and a TON more (which is why C++ is a shitty language, it's just a big mix bag of poop and candy, to eat the candy, you'll still need to put poop in your mouth). If you want to code modern applications, you'll use C# or java instead because the control and speed you get from C/C++ is not all that relevant on desktops/laptops today, not even on cellphones. Atm, I don't think pure C is used much outside of operating systems, both for PCs and machines.
I definitely think you should go ahead and get a good C book though. Learning C is a good investment since it teaches a lot of the concepts of programming without added abstraction. You can learn proper object oriented programming etc later on, when you know how loops, variables and such work.
On May 14 2012 18:32 Tobberoth wrote: I definitely think you should go ahead and get a good C book though. Learning C is a good investment since it teaches a lot of the concepts of programming without added abstraction. You can learn proper object oriented programming etc later on, when you know how loops, variables and such work.
You can learn the basics in just about any language, it makes absolutely no difference at rudimentary level. A loop is a loop in C or ruby.
Coding is about problem solving. Solve the problem first then start coding.
With that being said, it isn't immediately clear what OP's goal is, if application programming is the goal then C is perhaps not the most efficient starting point however C is a very influential language both in design and usage.
If OP only need a basic level of programming knowledge to compliment his degree then he should invest time into what ever tool his field uses e.g. Python is used for a lot of science projects, lisp in AI research...
If OP has no experience programming, I think Python is a pretty gentle introduction to "thinking like a programmer." It does provide lots of really nice (though a bit slow) high-level stuff that a lower-level language like C won't; list comprehensions and dynamic typing come into mind immediately. But Python is intuitive enough that we have an annual "Python spelling bee" at our school each winter, where contestants have to dictate (easy-ish) Python code without looking at a screen...
N.B. "low level" means "more control over the fine workings of the computer," whereas "high level" means "more large-scale, abstract tools." Both have their uses, and often higher-level languages [e.g. Python] are built over low-level languages [e.g. C]. C will help you learn a bit more about the workings of the computer--pointers, memory allocation, etc. Supposedly learning C helps you learn the huge plethora of C-like languages rather quickly. But again, if you've never done any coding, I think a higher level of abstraction will benefit you a lot.
Also, I feel like Java is a very... overburdened (???) language, in that it forces huge amounts of verbosity everywhere, since Java code is often meant to be enterprise code (or just shared development in general.) It's sort of a compromise between C and Python in terms of how much nice stuff it does for you automatically (garbage collection, object-oriented stuff, etc.)
Edit:
On May 05 2012 18:35 Abductedonut wrote:huge post on C
Oops, if OP really just wants to learn C, this post on page 3 seemed pretty decent.
Edit2: Wow I suck at reading threads, woo!
Anyway, to practice (and if you like math/algorithms), you can consider doing things like USACO training, TopCoder, and Project Euler. (Don't have to compete in the contests; just do the practice problems for fun!)