Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Page 1 of 3 123 LastLast
Results 1 to 8 of 19
  1. #1
    ziomatrixacs is offline Registered User
    Join Date
    Mar 2008
    Posts
    139
    Thanks
    0
    Thanked 1 Time in 1 Post

    Programing for beginners

    I know, I should probably take a computer programing course for this but I want to do this on my own time/budget for a hobby.. I was thinking about getting into programing with straight C (not C++) and basically... where do I start? Id just like to see what its like, and to see if I am any good at it. I know a little about C and have a book called "The indispensable guide to C" But I could always use more help. Im really not sure where to start typing the program, and that book is geard towards programing micro computers so some things arnt the same. (like it using LEDs on the micro computers carrier board, but my mac probably doesnt have the same names for the LEDs)

  2. #2
    nixgeek's Avatar
    nixgeek is offline Mac of the SubGenius! :-)
    Join Date
    Jan 2004
    Location
    Miami, FL
    Posts
    8,593
    Thanks
    32
    Thanked 157 Times in 141 Posts
    I've been thinking about getting into Python programming myself. There's a free (as in speech) manuscript called Think Python that I was referred to by someone on the IRC channels I frequent.

    http://www.greenteapress.com/thinkpy...inkpython.html

    Since you asked about programming in C, you could always check out the stuff that GNU has available for their compiler to get you started.

    http://www.gnu.org/doc/gnupresspub.html

    I believe Apple might also have something if you're going to be using Xcode. You could check at their developer page to see if there's anything.

    http://developer.apple.com/
    Apple iMac G5 17" (2 GHz G5) - Mac OS X 10.5.8/Ubuntu 10.04
    Asus Eee PC 901 (1.6 GHz Atom N270) - Fedora 13
    Apple Macintosh Quadra 650 (33 MHz MC68040) - Mac OS 8.1
    "JHVH-1" (2 GHz AMD Athlon XP 2400+) - Slackware 13.1

  3. #3
    ElDiabloConCaca's Avatar
    ElDiabloConCaca is offline U.S.D.A. Prime
    Join Date
    Aug 2001
    Location
    San Antonio, Texas
    Posts
    14,490
    Thanks
    10
    Thanked 648 Times in 610 Posts
    I would recommend using nothing but the Terminal to learn how to program C, as firing up XCode and trying to create a C program will just confuse most people. It seems as if you need some basic Terminal knowledge before you begin programming, though, specifically, but not limited to:

    - How to navigate your file system and view directory listings in the Terminal (ls, cd, etc.)
    - How to create and delete files (cat, rm, etc.)
    - How to create and remove directories (rmdir, rm -rf, mkdir, etc.)
    - How to create text files (vi, vim, nano, etc.)
    - How to compile programs (cc, gcc, g++, etc.)
    - How to execute the compiled programs (the dot-slash operator, etc.)
    - How to modify your $PATH variables

    This is what made me worry and think that:
    Im really not sure where to start typing the program...
    Any computer program is a text file, plain and simple, until you "compile" it. You would "type" the program wherever you would type plaintext normally, whether that be with TextEdit or some UNIX-y style Terminal text editor.

    I would start off with a good book on UNIX/Linux terminal navigation before learning C, simply because you need to. You'll actually learn a bit of C in the process, because UNIX and Linux are written in C, and a lot of command line programs and terminal commands are actually directives and functions in the C programs you'll be writing, as well.

    While you can learn C via XCode and without much Terminal knowledge, the Terminal and C are so integrated together that it would be a back-asswards way to learn how to program in C.

    Just a few cents worth of suggestions from someone who has taken the route of learning C in detail. Without Terminal knowledge, it is going to be hard to understand some of the concepts used in the C programming language.

    I do applaud your efforts to learn C, though, as most people skip straight to the higher-level languages (that are arguably easier to learn) like C++ and Java, without knowing much about what they're really doing. C makes you do everything manually (even manage how much memory you're using), and once you learn C, you'll have no trouble jumping right into other programming languages.

    Come back when you reach the section of C programming on "pointers" and we can help break it down into understandable terms -- if you don't need extra care and explanation walking through that part of the language, I'm sure NASA and the government will have six-figure job offers for you in no time...
    2009 Mac mini 2.0GHz • 2010 MacBook Air 11" • 2010 MacBook Pro 13" • LED 24" Cinema Display
    PowerMac G4 MDD dual 1.25GHz • PowerMac G4 Yikes! • iPad 2 32GB • 2 x iPhone 4 16GB • iPod Touch 8GB • iPod nano 1GB • iPod shuffle 1GB • AirPort Extreme dual-band • AppleTV
    http://www.jeffhoppe.com

  4. #4
    ziomatrixacs is offline Registered User
    Join Date
    Mar 2008
    Posts
    139
    Thanks
    0
    Thanked 1 Time in 1 Post
    Honestly I have no experience with terminal. To be frank, I see it as a dark and mysterious monster. I knew one could type a program into anywhere that edits text, I meant how do I compile it into something that "does something." I wasnt sure if I should use the term compiler or not there.

    So far, I know this..(or atleast think it)
    C is a lower level language.
    C can be used to make some games, in combination with MAYA. (MAYA will kill my ibook though)
    You use a compiler to turn the text into a program ( I dont know of any compilers of mac os x)
    I had x code on my ibook when I bought it from my friend, she didnt even know it was there but I deleted it. I think its on the OS X installation disc, I can get it with pacifist.
    One way to make a program "lighter" and easier is by defining a variable instead of using numbers.

    Example:

    This line uses 1
    This line also uses 1
    There is another line that uses 1

    If you find a problem and need to change 1 to something, say 2 then you must go through all of the lines and change it to 2. If you replace 1 with a variable, like A and set A=1 then you can easily change all of the numbers at once.

    Thats every thing I know, and I think I have a long road ahead.

  5. #5
    ElDiabloConCaca's Avatar
    ElDiabloConCaca is offline U.S.D.A. Prime
    Join Date
    Aug 2001
    Location
    San Antonio, Texas
    Posts
    14,490
    Thanks
    10
    Thanked 648 Times in 610 Posts
    That is a very basic understanding, yes, with some flaws (using variables does not relate to a "lighter" program).

    In your case, you may want to work on understanding some theory before diving in with straight-up programming. Don't even start on graphics yet -- for the next 2 years, you won't be programming a single graphic-based anything!

    And... learning how to program without knowing some basics about the Terminal is going to be very, very tricky. Programming is easy, but it's like riding a bike -- you will struggle and struggle and fall and fail, not knowing what you're doing wrong, trying to get the "hang" of it all, them BAM! -- one day, your mind will open and things will start to make a LOT more sense.

    I would highly recommend some courses in programming for someone of your experience. If you try and teach yourself, without knowing what you're really doing, it's going to be very difficult to tell if you're using the correct methods, or what, exactly, you're doing right, and what, exactly, you're doing wrong. You can follow examples in the book, but books don't answer questions that you may have. Books can't watch over your shoulder and tell you when you're heading down the wrong path, and why that path isn't the most efficient one.

    Programming is tough, and it requires a lot of background in math, as well. A basic understanding of Algebra isn't going to cut it, unless you simply intend to use your programming knowledge to make very, very simple programs.

    I think that programming is best taught in a course-style curriculum, and 75% of those courses have nothing to do with computers at all. "Programming" isn't just about writing code on a computer -- it's a collection of knowledge from different disciplines, including math, science, physics, and yes -- computers.

    It's a ton of friggin' work, but I think it very worth it and it's extremely rewarding in a lot of aspects.

    I wish you the best of luck, but with what limited information we have about you and what knowledge and level of mathematical education you have, I must suggest taking a different route to programming other than by book. While some, I'm sure, have self-taught themselves out of a book, I would think that the vast majority of people in your situation ended their programming careers in frustration rather than completing the task and really knowing how to "program" a computer.

    Good luck!
    2009 Mac mini 2.0GHz • 2010 MacBook Air 11" • 2010 MacBook Pro 13" • LED 24" Cinema Display
    PowerMac G4 MDD dual 1.25GHz • PowerMac G4 Yikes! • iPad 2 32GB • 2 x iPhone 4 16GB • iPod Touch 8GB • iPod nano 1GB • iPod shuffle 1GB • AirPort Extreme dual-band • AppleTV
    http://www.jeffhoppe.com

  6. #6
    ziomatrixacs is offline Registered User
    Join Date
    Mar 2008
    Posts
    139
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well, Ill give a little back ground info when it comes to academics and relevant stuff.

    When it comes to math, I am a bit of an odd ball. From 1st to 4th grade, I liked math, it made sense. I could visualize it. You have 5 boxes, and you put 2 apples in each box then you have 10. Or, 5x2=10. But once algebra and that “crap math” hit me, it was all down hill. Made no sense what so ever. And to be blunt, I didnt give a crap about square roots and pi and rational numbers.[i]I was never going to use that any way.[\i] Ill admit, from 5th to 12th grade, I passed simply because I showed up and acted like I cared. And on top of that, I was taking all “basic” classes. But some how I managed to slip though the cracks in my senior year and ended up taking the hardest course, with the strictest teacher in the school district: Physics. Physics was a course you had to ask for and you must meet a certain criteria and former math teachers must recommend you. I asked my guidance counselor about it, and she wiggled me in some how. Heck, my one math teacher said I should NOT take physics, and wouldnt allow me to take Calculus with her. I ended up with the lower, Pre calc instead. Since its hard to get into physics, only the “smart” kids were in that class. No goof-offs, just the kids with real high GPA’s. It was me, the one who could not rearrange 5=1*x to solve for x and then the kids taking college level calculus. (The school is a 5 minute walk from a college!) But some how, I ended up passing that class in the top 4% with an A-. How did I get such a grade in such a class? For the first time in years, math made sense. I could visualize two objects colliding, a ball falling off a roof, a cannon shooting over a mountain, I could even apply this to real life situations!
    Ironically, the most intense math course of the SD was “easy” to me. I still review my notes ever now and then. Of course I did spend most of my lunch time with my precalc teacher, she taught me some basic algebra.
    How did precalc go you may be wondering? I nearly failed. I only passed because of the work she knew I was capable of.
    So, right now, I think I have the potential to be pretty good at math as long as I enjoy it. I like to think of physics as “math with a GUI.” As for those “pure” math classes like calc, I suck at it.

    Other possible relevant stuff..A while back I used to be big into Legos. Ever since I was One, I built robots and stuck motors spinning rubbing bands to axles powered by a 9volt battery for locomotion. I ended up getting 2 RCX’s and a Scout but never really programed them. I always preferred to remotely control them.
    In my free time I build, design and fly model airplanes.. I build the small ones 40” and under. I also fly (my friends) giant 1/3rd scale gas models planes. I used to fly RC helicopters but there was too much B/S involved. Hence my decision to join the AirForce. By the way, ever since I started model aviation, in 7th grade, I have been using bits and pieces of math that I understood only because it was relevant to airplanes. Looking back, I realize I was actually doing very crude algebra, and using physics concepts. Only I didnt know I was doing algebra and physics! (Example, wing loading IS pressure, I just had no idea) Thats why I said [i]I was never going to use that any way.[\i]

    Im just now getting seriously interested in computers. I dont have much money, (income is from painting (Im an artist too)) so my greatest limit is the machine I can afford. And it is a 100% stock Ibook G4 (no ram upgrade or anything!) I cant run any PC applications unless if I run Q emulator but I have yet to figure out how to down load it. I also dont want to use my XP key on it, saving that for when I get my macbook pro! Id like to play with Ubuntu Linux, but I am having ISP problems, so Id I have to either get it on CD or through a bittorrent file. Id rather avoid that bittorrent BS though.


    I tried getting Xcode, thought it was on my ibooks CD’s that came with it. I used Pacifist and couldnt find anything so I began looking over the C book I have.. its about 800 pages of pure C!
    This is the first intro program..
    I think I typed it right, I typed it like the picture. I put it into terminal and it reports an error.
    The book mentions Borlands Turbo C alot, not sure if I need that. In the book, it shows diagrams for both MS-DOS and UNIX.

    #include <stdio.h>

    int main( void )
    {
    printf("Hello World! \n" ) ;
    return 0 ;
    }

    This is the error:

    Last login: Mon Dec 8 23:01:54 on ttyp2
    Welcome to Darwin!
    Joseph-C-iBook-G4:~ Joey$ #include <stdio.h>
    Joseph-C-iBook-G4:~ Joey$
    Joseph-C-iBook-G4:~ Joey$ int main( void )
    -bash: syntax error near unexpected token `('
    Joseph-C-iBook-G4:~ Joey$ {
    > printf("Hello World! \n" ) ;
    -bash: syntax error near unexpected token `"Hello World! \n"'
    Joseph-C-iBook-G4:~ Joey$ return 0 ;
    -bash: return: can only `return' from a function or sourced script
    Joseph-C-iBook-G4:~ Joey$ }






    The guy who gave me the book, also gave me a micro computer to play with. It came with a compiler for C++. I installed it onto my desktop running XP. The desktop has been giving me straight crap since the ISP shut the internet off. It shuts off for no reason, but thats another problem. I havent been able to use the included compiler because the desktop is just so darned...well, PC’ish Which is why I REALLY would rather learn how to make programs for the mac. Atleast the hardware is much much more stable. My experience with RC planes comes into handy. I know to start small, every once in a while you will come a cross a guy trying to scratch build a 1/4th scale Edge 540 or a Turbine Jet helicopter...projects that take years of experience. I dont intend to start building full operating systems or anything, Id just like to acquire the tools I need to create a simple program, like a very simple + - / * calculator. If I could get that far, Id be satisfied (for a short period of time of course!) If I like it, I might pursue an education in it (on AF’s tab!) But id really hate to start a course and not like it, when I could be using it for something I need or enjoy..

    So here are some questions I have came up with.. what is/are the compiler that I could use with Mac OS x 10.4? Is there any sample code I could look at? How do I get a program to run? (I know Windows uses .exe files, what do I need with a mac?) What is the difference between xcode and terminal? How powerful is terminal?

    Im trying the K.I.S.S. method here

  7. #7
    ElDiabloConCaca's Avatar
    ElDiabloConCaca is offline U.S.D.A. Prime
    Join Date
    Aug 2001
    Location
    San Antonio, Texas
    Posts
    14,490
    Thanks
    10
    Thanked 648 Times in 610 Posts
    I'll just jump straight to the questions, and say that's quite a path to take to enlightenment. It's nice to hear someone take passion in something out of curiosity and because somewhere they learned what (I think) everyone learns at some point in their life: you're a lot damn smarter than you have been led to believe. It just takes extraordinary circumstances to bring it out.

    First, get XCode for your iBook. Apple should be offering an XCode that is compatible with PowerPC processors, if the latest version isn't PowerPC-compatble (I think it is, but...). You may need to sign up for a "Free" Developer's Account at http://developer.apple.com. It's no trouble, and will allow you to download XCode. Choose the version that is compatible with the version of OS X you're running. Install it. Along with a bunch of cool GUI tools (that you won't use at this moment), it also installs the necessary command-line compiler tools you need.

    At any rate, let's see... you've gotten to the point where you type a program -- good. Take that same program you have, and save it into a text file. Save it as "program1.c" on your Desktop, in plain-text format (TextEdit has an option for this).

    Then, launch the terminal, and type the following command verbatim:
    Code:
    cd ~/Desktop
    ...and press Enter.

    Then, type:
    Code:
    gcc -o program1 program1.c
    That "compiles" your "source code" (the code you typed) into an "executable binary" program -- basically, "gcc" (the compiler) interpreted your code, line-for-line, and turned it into something the computer can understand. Now, you've got an executable program that will run on Mac OS X on the command line.

    I'll break that last command down, word-by-word, because that's the syntax you'll use most of the time to compile simple C programs...
    "gcc" -- the compiler. In the terminal, whenever you type something at the command line, the first "word" you type is a program, or some binary built-in to the bash shell (that's the name of the Terminal program or environment you're using -- even the Terminal itself is just a program). Everything after that, separated by spaces, are "arguments" to the program to tell it to do something.

    The next two arguments go together:
    "-o program1" -- means, "Make the output of this program (the gcc program) into the executable "program1" instead of "a.out" (which is what you get if you omit the "-o [executable name]").

    After that, we have this:
    "program1.c" -- the "input" to the gcc program (compiler). Gotta tell the compiler which source code to compile, right?

    So, altogether we have a terminal "statement" that would look something like this in English:
    Code:
    gcc, please compile a program and make an executable called "program1" using my source code "program1.c"
    Almost every UNIX program (something typed in the Terminal) can take "arguments" after the program name to modify and/or specify the way in which the program runs and what it does.

    After you run through all that, to run your program, type this:
    Code:
    ./program1
    And, you should see "Hello, world" printed on your screen.

    The "./" in front of the executable name tells the Terminal to "execute" the program located in the current directory ("./") named "program1."

    If you wanted to execute a program named "program1" in your "Music" folder that is located in your home folder, you would type:
    Code:
    ~/Music/program1
    The "~" is shorthand for "home folder", and the rest is self-explanatory: "home folder" -slash- "Music folder" -slash- "program1".
    2009 Mac mini 2.0GHz • 2010 MacBook Air 11" • 2010 MacBook Pro 13" • LED 24" Cinema Display
    PowerMac G4 MDD dual 1.25GHz • PowerMac G4 Yikes! • iPad 2 32GB • 2 x iPhone 4 16GB • iPod Touch 8GB • iPod nano 1GB • iPod shuffle 1GB • AirPort Extreme dual-band • AppleTV
    http://www.jeffhoppe.com

  8. #8
    Viro's Avatar
    Viro is offline Registered User
    Join Date
    Nov 2003
    Location
    Oxford, UK
    Posts
    2,497
    Thanks
    0
    Thanked 2 Times in 2 Posts
    You're not supposed to type code directly into the terminal. You're supposed to type it into a text editor and then save it as a .c file. So open up a text editor like TextEdit (make sure that it isn't saving in RichText), type in the code, save it into a file with .c as an extension (e.g. hello.c) and then drop down to the terminal.

    Then follow ElDiablo's instructions on how to get that file compiled into a binary that you can run.

 

 
Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •