Thread: very basic c

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    11

    very basic c

    I'm learning c and have put my learning to the test, and failed. When I compile, It stops at the first printf. I thank you for looking and helping...

    Code:
    #include <stdio.h>
    #main ()
    class array
    
    {
    
    char         color [8];
    char         feet   [8];
    char         food [15];
    int            age;
    
    printf       ("/n What color is your hair?");
    scanf   ("%s",   &color);
    
    printf       ("/n %s!, I think u should cut it!!!",   color);
    
    printf       ("/n Do u have big or small feet?");
    scanf        ("%s", feet");
    
    printf       ("/n How old r u?");
    scanf        ("%d",   age);
    
    prinf         ("/nTell me what your favorite kind of food is");
    scanf         ("%s",   food);
    
    printf        ("/n I like %s too!",   food);
    printf	      ("/n So far I have found out that your hair color is %s, your feet r %s, and u are %d years old and u love to eat %s.", color, feet, age, food);
    
    return       (0)
    
    }
    Last edited by Salem; 01-17-2011 at 01:28 AM. Reason: Added [code][/code] tags - learn to use them yourself

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    When you compile it stops at the first printf! How does it even get past #main (), let alone "class array"?

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    I'm not sure, ok back to the drawing board...

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    Quote Originally Posted by tabstop View Post
    When you compile it stops at the first printf! How does it even get past #main (), let alone "class array"?
    ummm... maybe u can't read but this is my first attempt at a simple program.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by jayparrillo View Post
    ummm... maybe u can't read but this is my first attempt at a simple program.
    Um ... no. This is not an attempt at a simple program. Once you've done a little bit more reading, then you can make your first attempt at a simple program.

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    First thing first: << !! Posting Code? Read this First !! >>

    Now on to the problem with your code. You are indeed very new and I suggest you go back through your book/tutorials and redo some of them. You have missed some fundamentals of C programming.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by jayparrillo View Post
    ummm... maybe u can't read but this is my first attempt at a simple program.
    Ummm... insulting your helpers is not a good way to motivate them.

    class and array are not even C keywords... how did you come up with them?

    The correct form of the "smallest possible program" is:

    Code:
    #include <stdio.h>
    
    int main (void)
      {
          puts("hello world");
      }
    Every console program in C builds from this foundation.

    Moreover... If my old boss ever saw this
    Code:
    printf ("/n How old r u?");
    on a computer screen, I'd have been looking for a new job.

    Programming is all about knowing the Grammar and Spelling of a language... there's no excuse for a programmer who can't even manage a simple sentence...

  8. #8
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by CommonTater View Post
    Moreover... If my old boss ever saw this
    Code:
    printf ("/n How old r u?");
    on a computer screen, I'd have been looking for a new job.

    Programming is all about knowing the Grammar and Spelling of a language... there's no excuse for a programmer who can't even manage a simple sentence...
    lol!
    You ended that sentence with a preposition...Bastard!

  9. #9
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    Quote Originally Posted by CommonTater View Post
    Ummm... insulting your helpers is not a good way to motivate them.

    class and array are not even C keywords... how did you come up with them?

    The correct form of the "smallest possible program" is:

    Code:
    #include <stdio.h>
    
    int main (void)
      {
          puts("hello world");
      }
    Every console program in C builds from this foundation.

    Moreover... If my old boss ever saw this
    Code:
    printf ("/n How old r u?");
    on a computer screen, I'd have been looking for a new job.

    Programming is all about knowing the Grammar and Spelling of a language... there's no excuse for a programmer who can't even manage a simple sentence...
    Ok, I see I'm going to have to spell this out to u pros in programming c. I am a new to programming and have read a really good beginners book. I have also read and went through many online tutorials and wanted to attempt the most basic of a c program without being "hello world". Now with that being said, I'm not worried about spelling or punctuation, just wanted to post my simple, basic, beginners program and have a pioneer throw me a tip or two so it will compile. Yes I'm sure there are basic mistakes because. I didn't copy and past then change some words that would be displayed on screen, I attempted this and referenced a few areas and still stumbled. If u can offer a tip, great! Im willing to take my spanking but if u want to spank me with no help, *&%*$,u! Lol... have fun a little.

  10. #10
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    :O and in the "really good book" where did they use
    #main() or class array?

    tabstop was simply pointing out your error, why take it as an insult?

    Anyways, did you solve your problem?
    You ended that sentence with a preposition...Bastard!

  11. #11
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    I kind of agree with the OP here.

    He has managed to avoid most of the pitfalls that newcomers to the board have, yet has been welcomed with some pretty poor elistest advice. He has tried the problem first, he has posted his code (obviously not copied from anywhere) and has asked very humbly for help. I figured that this was the type of person that cboard looked to help, and not to turn away.

    I'm sure the OP knows that he needs to read more books, the fact that his first program is not running and he does not understand why probably tells him this. Helping him getting his first program running is probably more motivation to learn more about C than "Read more books".

    (I realise that a negative view towards OP was probably festered after he reacted to tabstop's first post. While I don't think tabstop's post was all that harsh, if I was a beginner I probably would have interpreted it more as patronising than giving hints to where I went wrong)

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by jayparrillo View Post
    Ok, I see I'm going to have to spell this out to u pros in programming c. I am a new to programming and have read a really good beginners book.
    That's good... but where did you get the idea for, well, what you had...

    I'd be pretty sure that didn't come out of the book and since every programming book I've been into uses dozens of examples you had to have seen the main() function at least a hundred times.

    I have also read and went through many online tutorials and wanted to attempt the most basic of a c program without being "hello world".
    Do you know why the first program a C or C++ programmer writes is always "hello world"?

    It's not some silly tradition (well it is but it's not silly) and it's not even a learning tool... It's done to *test your compiler* to make sure you have it set up correctly. This is not something to be skipped over and ignored...

    Now with that being said, I'm not worried about spelling or punctuation, just wanted to post my simple, basic, beginners program and have a pioneer throw me a tip or two so it will compile.
    Tip #1... Having more than 40 years in the electronics, computers and programming, 10 of that in management, I can tell you with pretty reasonable authority that "I'm not worried about spelling or punctuation" isn't going to get you the job... and it's not going to give you a working program!

    Tip #2 ... This time actually read the books and do the assignments.


    Im willing to take my spanking but if u want to spank me with no help, *&%*$,u! Lol... have fun a little.
    The whole point is that your general disregard for good grammar in your prose is also what's going to trip you up as a programmer... No matter which language you tackle, C, C++, Python... English... it is always about precise communication. If you don't cultivate those skills now, their lack will haunt you for the rest of your time at the keyboard.

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    So, have you fixed your code yet? Is it still causing problems? One thing you should know is that a newline character is not /n, it's \n.

  14. #14
    Registered User
    Join Date
    Dec 2010
    Posts
    4

    What I noticed

    Have you fixed your code yet? The first thing I noticed is; you need to put an & in front of age.

  15. #15
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    He needs to do many things.
    remove #main and set it as int main()
    no such thing as class array..I have no idea where he saw that in a C book...
    printf(..) instead of prinf(..)
    a semi colon after return 0..

    as he is not replying maybe he has fixed it...?
    You ended that sentence with a preposition...Bastard!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Programm giving Error
    By dharmil007 in forum C Programming
    Replies: 16
    Last Post: 05-27-2010, 02:01 PM
  2. [ANN] New script engine (Basic sintax)
    By MKTMK in forum C++ Programming
    Replies: 1
    Last Post: 11-01-2005, 10:28 AM
  3. what are your thoughts on visual basic?
    By orion- in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-22-2005, 04:28 AM
  4. visual basic vs C or C++
    By FOOTOO in forum Windows Programming
    Replies: 5
    Last Post: 02-06-2005, 08:41 PM