C tutorials for a beginner

Member
Posts: 51
Joined: 2005.07
Post: #1
does anyone know of *GOOD* beginner tutorials for C? post them, please.
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #2
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
Quote this message in a reply
Member
Posts: 51
Joined: 2005.07
Post: #3
thanks. i have a question. is there a link between cocoa and c?
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #4
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.
Quote this message in a reply
Member
Posts: 51
Joined: 2005.07
Post: #5
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?
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #6
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)
Quote this message in a reply
Member
Posts: 51
Joined: 2005.07
Post: #7
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?
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #8
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
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #9
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.
Quote this message in a reply
Member
Posts: 51
Joined: 2005.07
Post: #10
type that in the terminal?

and i write the code in textedit?
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #11
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).
Quote this message in a reply
Member
Posts: 51
Joined: 2005.07
Post: #12
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;
}
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #13
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.
Quote this message in a reply
Member
Posts: 51
Joined: 2005.07
Post: #14
explain the
Code:
fflush(stdin);
please

and in the scanf("%8s", name);
the 8 means only take 8 letters?
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #15
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.
Quote this message in a reply
Post Reply