Stumbled onto a brilliant C tutorial.

Posts: 90
Joined: 2006.11
Post: #1
While looking for Java tutorials, I found a C one instead.

I understood everything one first read. I know what exactly are 'pointers'. Recommend this to all beginners. (For MacOS X programming newbies, I recommend knowing how the command line works first...)

Although there is something it hasn't told me: Why pointers? Are they faster to manipulate than directly with the variables itself?

Although I find that C commands are all abbreviations of what they actually do... takes a while to wrap your head around it.
Quote this message in a reply
Posts: 1,487
Joined: 2002.09
Post: #2
Wow, what a coincidence. That's the tutorial my Operating Systems prof had us look at today. I think that I was the only one who had used C before.

Pointers have a ton of uses, some common ones are:
- Using a variable that's not a local variable of your function.
- Working with arrays. (arrays are just pointers to the first element)
- Using dynamic memory. (Using a block of memory)

Using pointers will make your code mildly slower, because to dereference the pointer you need to load the address and then the memory it points to. Don't worry about it though, it's not likely to be a performance problem.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Posts: 90
Joined: 2006.11
Post: #3
I think thats because we both use google. hehehe.
EDIT: even more brilliant one:
Quote this message in a reply
Post: #4
I want to learn C really, REALLY, bad (sick of basic) and the code on the first site that was linked to didn't work for me. The terminal says that the void is not an int or something like that. H4lp!?

What I did was write a text file in simpletext (provided as a project with the OSX developer install, I compiled it) and copy-pasted the hello world code. I changed the format of the file to .c and tried to compile it using gcc Main.c (the name of the file was Main.c)

What am I doing wrong?
Quote this message in a reply
Posts: 245
Joined: 2005.11
Post: #5
What that error message is telling you is that in C++, the main() function has to return an int, whereas C is happy for main() to return void. The code is valid C, but the compiler is trying to compile it as C++ and, therefore, returning this error.
Unfortunately I haven't used gcc from the command line for years (I use Xcode - give it a try!) so I'll have to refer you to the man page (type "man gcc") for more info, but check that your file has a lower case .c file extension, as upper case would mean it was a C++. Also try the -c99 option.
Quote this message in a reply
Posts: 1,403
Joined: 2005.07
Post: #6
#include < stdio.h>
void main()
    printf("\nHello World\n");

should be

#include <stdio.h>
#include <stdlib.h>

int main(void) {
puts("Hello, World!");

*doesn't like this tutorial*

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Post Reply