Stumbled onto a brilliant C tutorial.

Member
Posts: 90
Joined: 2006.11
Post: #1
While looking for Java tutorials, I found a C one instead.
http://einstein.drexel.edu/courses/CompP...html#first

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
Sage
Posts: 1,482
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
Member
Posts: 90
Joined: 2006.11
Post: #3
I think thats because we both use google. hehehe.
EDIT: even more brilliant one: http://cocoadevcentral.com/articles/000081.php
Quote this message in a reply
phlogios
Unregistered
 
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
Member
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
Sage
Posts: 1,403
Joined: 2005.07
Post: #6
Code:
#include < stdio.h>
void main()
{
    printf("\nHello World\n");
}

should be

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

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

*doesn't like this tutorial*

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