iDevGames Forums
C tutorials for a beginner - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: C tutorials for a beginner (/thread-5045.html)

Pages: 1 2


C tutorials for a beginner - Tyaedalis - Sep 11, 2005 04:49 PM

does anyone know of *GOOD* beginner tutorials for C? post them, please.


C tutorials for a beginner - Andrew - Sep 11, 2005 04:58 PM

Try this one:

http://www.eskimo.com/~scs/cclass/notes/top.html

or, if you want something simpler & less detailed:

http://www.cocoadevcentral.com/articles/000081.php


C tutorials for a beginner - Tyaedalis - Sep 11, 2005 05:16 PM

thanks. i have a question. is there a link between cocoa and c?


C tutorials for a beginner - Andrew - Sep 11, 2005 05:24 PM

Tyaedalis Wrote:thanks. i have a question. is there a link between cocoa and c?

The language of choice for Cocoa programming is objective-C. Objective-C is a true superset of C. That means that objective-C is C with stuff added to it. If you want to start writing plain C code in the middle of an objective-C method, you can do so.


C tutorials for a beginner - Tyaedalis - Sep 11, 2005 05:30 PM

am having trouble with the
Code:
#include <stdio.h>

i dont know what the stdio.h means

i kow it means standard something, but what does it do?
does the program need it?

also, how do i set up Xcode for C compiling?


C tutorials for a beginner - Andrew - Sep 11, 2005 05:32 PM

BTW, have you ever programmed before (in any language)?
If you haven't, you should consider learning Python. It's simple and makes a great first language. Here's a great (free) book to learn from: How to Think Like a Computer Scientist: Learning with Python (PDF)


C tutorials for a beginner - Tyaedalis - Sep 11, 2005 05:34 PM

i have learned the basics of BASIC Rasp but i cant remember anything from it. i tried learning C before recntly, but got distracted... pythons seems boring. what can you do with it and how do you compile (or interperet) it?


C tutorials for a beginner - Andrew - Sep 11, 2005 05:46 PM

Tyaedalis Wrote:am having trouble with the
Code:
#include <stdio.h>

i dont know what the stdio.h means

i kow it means standard something, but what does it do?
does the program need it?

also, how do i set up Xcode for C compiling?

#include someFile means "paste the contents of someFile here". You'll find stdio.h in /usr/includes/stdio.h. It defines a bunch of stuff (like the printf function) which allows your program to get input an produce output (hence, the io part).

You don't need Xcode for plain C (although it helps once you start making more complex programs). Use GCC for now. Here's how:

1) open Terminal

2) cd to the directory of your source code (if you don't know how to use a command line, google for "basic unix tutorial")

3) type gcc myFile.c -o whateverYouWantToCallYourProgram

4) run it by typing ./nameOfYourProgram


C tutorials for a beginner - Andrew - Sep 11, 2005 05:51 PM

Tyaedalis Wrote:pythons seems boring. what can you do with it and how do you compile (or interperet) it?

Ever heard of BitTorrent? That was written in Python.

To run a Python program, just type python nameOfMyPythonProgram.py

There's no need to compile your code before running it.


C tutorials for a beginner - Tyaedalis - Sep 11, 2005 05:55 PM

type that in the terminal?

and i write the code in textedit?


C tutorials for a beginner - Andrew - Sep 11, 2005 06:03 PM

Tyaedalis Wrote:type that in the terminal?

and i write the code in textedit?

Yes. Although, you can write the source code in any text editor you like (including Xcode). If you want to write it in TextEdit, make sure you save it as plain text (not RTF).


C tutorials for a beginner - Tyaedalis - Sep 11, 2005 06:07 PM

ok, i got the normal
Code:
print "Hello, World!"

done. it's exactly the same as BASIC.

i think i will just jump into C, caus ei started on c and i like it.

i wrote this a while back in C:
Code:
#include <stdio.h>
  
int main()
{
  char name[20], age[9];
  printf("\nWhat is your name?  ");
  scanf("%s", name);
  printf("How old are you?  ");
  scanf("%s", age);
  printf("Your name is %s, and you are %s years old.\n", name,age);
  return 0;
}



C tutorials for a beginner - Andrew - Sep 11, 2005 06:33 PM

Be careful. There is a SERIOUS buffer-overflow problem with that program. Try entering a really long name and age.

One solution is to limit the number of character that scanf will read:

scanf("%8s", name);
fflush(stdin);

Note that I used 8 instead 9. That's because a C string is an array of characters which end in the NUL character ('\0').

Python hides these kinds of details for you.


C tutorials for a beginner - Tyaedalis - Sep 11, 2005 06:45 PM

explain the
Code:
fflush(stdin);
please

and in the scanf("%8s", name);
the 8 means only take 8 letters?


C tutorials for a beginner - Andrew - Sep 11, 2005 06:54 PM

yes, "%8s" means read up to 8 characters.

fflush(stdin) means empty the standard input buffer so that the next time I call scanf(), there won't be junk in the buffer.