Results 1 to 10 of 25
Hello, I'm trying to learn C and I have found a couple of guides that are kind of nifty while Googling. Although the guides are old (1990's) they are still ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-18-2005 #1
Just starting C and I feel hopeless
Hello, I'm trying to learn C and I have found a couple of guides that are kind of nifty while Googling. Although the guides are old (1990's) they are still good for beginners like myself I suppose. I feel quite newbish for bringing my problem up but I can't even get my first program to run..
To top it all off it's only a Hello World like program
Here is what I have:
I saved it as "file.c" yet this is the output:Code:#include <stdio.h> main() { printf("This is a C program\n"); }
So it returns with a blank line? I thought I was supposed to get an output of "This is a C program". Maybe I'm too noobish to realize that this is too small of a program and I'm not supposed to get any output but I thought it would do _something_ I dunno. My friend writes in C but says he is too busy to help me and that if I'm lucky I can borrow his C howto book :PCode:$ gcc file.c $
I know this is a foolish question to ask, but I need to start learning somewhere and somehow. Thanks.Registered Linux user #393103
- 11-19-2005 #2Linux Engineer
- Join Date
- Jan 2005
- Location
- Chicago (USA)
- Posts
- 1,028
Basic compiling with GCC: gcc SOURCE -o EXECUTABLE'S-NAME. Then execute the executable like you would a shell script or any other program.
- 11-19-2005 #3
Since gcc is ANSI compliant, you should put int main(void) rather than main(). Then just have a return 0 at the end of the code i.e.:
For small programs it may be ok to do void main void... but when creating larger programs, you need to let the system know when the program has finished successfully, otherwise you may get wierd errors (Only for very large programs).Code:int main(void) { printf("This is a C program\n"); return 0; // tells the system program has finished successfully. }Life is complex, it has a real part and an imaginary part.
- 11-19-2005 #4Just Joined!
- Join Date
- Jun 2005
- Location
- Canada, Halifax
- Posts
- 86
The one and only C programming manual that you'll ever need is "The C Programming Language, Second Edition" ISBN 0-13-110362-8. I _HIGHLY_ recommend that you buy this book.
I've taken a number of C and C++ programming courses during my days in university but none have stood the test of time once I got into industry. It (K&R) won't help you with "gcc" and other application and platform specific issues however it is the one and only souce needed for anyone interested in mastering C.
To help out with the sorst of questions that you just presented here, get "Beginning Linux Programming, 3rd Edition" ISBN ISBN: 0-7645-4497-7. This book will help answer your "Hello, world!" gcc questions all the way through to much more advanced topics.
I appreciate that you're enthusiastic and want to start programming right away (go for it!) but it is well worth your valuable time to get these books. I have them both in my personal library and always will!
- 11-19-2005 #5
ok thanks guys.
hate to do it but I might go along with the majority and start learning C++ maybe.. C is fun and all but I want something heavily based on object orientation and such and I think C++ would just suit me a bit more. Afterwards I might go back into C and possibly Java or something later.
Thanks again for the help.Registered Linux user #393103
- 11-19-2005 #6
One thing you should keep in mind is that C is just a subset of C++. If you learn C, then C++ is just C with objects, nothing more. By learning one, you automaticially know the other.
And good luck with your programming studies.Life is complex, it has a real part and an imaginary part.
- 11-19-2005 #7oh.. eh, in that sense it seems that C++ is actually a bit more useful but C is there to say that I'm a "1337 h4x0r"?
Originally Posted by AlexK
Getting serious - I can see the pros and cons to each I suppose, I do think that I might want to go with C++ maybe..
I did finally figure out why it was returning a blank line, I was only compiling it. I had to run the a.out file that was generated later
. But I guess you can make all sorts of stupid mistakes when you're learning :P wow, I did feel really stupid though. My face was this guy:
Registered Linux user #393103
- 11-19-2005 #8Linux Engineer
- Join Date
- Jan 2005
- Location
- Chicago (USA)
- Posts
- 1,028
No, that's Objective C. C++ has some more.
Originally Posted by AlexK
http://en.wikipedia.org/wiki/C_plus_plus
http://en.wikipedia.org/wiki/Objective_C
And GCC4 does compain if main isn't an int.
- 11-19-2005 #9Yep, Ubuntu installed GCC4 and it complained when I didn't have the int in there, unfortunately all the documentation out there says little to nothing about this. I think I'm going to go pick up The C Language book.
Originally Posted by a thing Registered Linux user #393103
- 11-19-2005 #10Just Joined!
- Join Date
- Jul 2004
- Posts
- 94
I am not really looking to change any opinions or start a flame war, but I feel like I should express my opinion on the issue, even if very briefly.
George Harrison, C++ is a wonderful language, and learning it will stand you in good stead in the long run. (I firmly believe that it is important to acquire at least a cursory acquaintance with many different languages even when one knows two or three very deeply.)
But it is wrong to assume that object-oriented programming is not possible with C. In fact, very well written C code can be conceptually equivalent to C++ code. (An example is the GTK+ library, written in C, but in object-oriented fashion.) Object-oriented programming should be seen as a means of implementing a particular method of solving a problem, not as a constraint to use a particular programming language. In fact, programming in object-oriented style in C will really force you to plan your solution carefully, and in the process, develop good programming habits.
Don't shun C simply because it does not have the "class" keyword in it. In my opinion it is the best language to learn. I know that there will be those who disagree with the last statement, but I will stand by it.


Reply With Quote
