View Full Version : Stumbled onto a brilliant C tutorial.
leRiCl
2007.01.19, 12:24 AM
While looking for Java tutorials, I found a C one instead.
http://einstein.drexel.edu/courses/CompPhys/General/C_basics/c_tutorial.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.
Skorche
2007.01.19, 01:11 AM
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.
leRiCl
2007.01.19, 01:46 AM
I think thats because we both use google. hehehe.
EDIT: even more brilliant one: http://cocoadevcentral.com/articles/000081.php
phlogios
2007.10.12, 10:29 AM
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?
backslash
2007.10.12, 04:24 PM
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.
unknown
2007.10.12, 05:06 PM
#include < stdio.h>
void main()
{
printf("\nHello World\n");
}
should be
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("Hello, World!");
return EXIT_SUCCESS;
}
*doesn't like this tutorial*
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.