Thread: very basic c

  1. #16
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    Quote Originally Posted by Eman View Post
    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...?
    I will have to fix it once I get home, I see that I have made some silly mistakes and im excited to fix them. Thank u soooooo much for lending knowledge that is much needed. "Class array" yea.. what was I thinking? The typo, it was late and I was frustrated towards the end. I truly thank u guys. If it doesn't compile after my corrections, I'm sorry to say I'll be back.

  2. #17
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by jayparrillo View Post
    If it doesn't compile after my corrections, I'm sorry to say I'll be back.
    don't be sorry..i do it all the time! lol!
    You ended that sentence with a preposition...Bastard!

  3. #18
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    I also see that I cannot scan input with spaces useing scanf. I think it will be easier to use (gets) and (puts) so the user may use sentences if need be. I hope that I'm making the right decision.

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,334
    Quote Originally Posted by jayparrillo View Post
    I also see that I cannot scan input with spaces useing scanf. I think it will be easier to use (gets) and (puts) so the user may use sentences if need be. I hope that I'm making the right decision.
    gets is automatically the wrong decision. Try fgets instead.

  5. #20
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    I replied and don't see it so I will post again. I will make my corrections when I get home and I'm excited about haveing a working program. Im going use (putc) and (gets) instead of printf and scant due to the spaceing issue.

  6. #21
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    we saw it...

    use fgets as tabstop+ said

    Cprogramming.com FAQ > Why gets() is bad / Buffer Overflows
    You ended that sentence with a preposition...Bastard!

  7. #22
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    Quote Originally Posted by tabstop View Post
    gets is automatically the wrong decision. Try fgets instead.
    (puts) and (gets)
    Hummm....
    Let me research fgets, good to know about the over flow issue.
    Thank you for that link, I will most certianly use (fgets).
    Eman.... I thank u! I'm so new and continue to learn and its guys like u that help us newcommers stay motivated.
    Last edited by jayparrillo; 01-17-2011 at 05:37 PM.

  8. #23
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    #include <stdio.h>
    #include <string.h>

    main ()

    {

    char color [15];
    char feet [8];
    char food [25];
    int age;

    fputs ("What color is your hair?\n");
    fgets ("%s", &color);

    fputs ("%s!, I think u should cut it!!!\n", color);

    fputs ("Do u have big or small feet?\n");
    fgets ("%s", feet);


    fputs ("How old r u?\n");
    fgets ("%d", age);

    fputs ("Tell me what your favorite kind of food is\n");
    fgets ("%s", food);

    fputs ("I like %s too!\n", food);

    return (0)

    }

  9. #24
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    lol, major bad on that attempt WOW! I'm too tired to research it now so I will try tomorrow after work. I thought it would be much closer than my last one, know one said this was going to be easy and so far it's not.

  10. #25
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    Quote Originally Posted by Shakti
    You have to read that first, before posting code. That is why it's called "Posting Code? Read this First".

    fgets is not like scanf, it doesn't take the format of the input as an argument.

    (fgets - C++ Reference)
    Code:
    char * fgets ( char * str, int num, FILE * stream );
    
    str
        Pointer to an array of chars where the string read is stored.
    num
        Maximum number of characters to be read (including the final null-character). Usually, the length of the array passed as str is used.
    stream
        Pointer to a FILE object that identifies the stream where characters are read from.
        To read from the standard input, stdin can be used for this parameter.
    This is the function declaration of fgets, it tells you what you have to give to the function and what it gives to you.

    The first thing to supply to fgets is the string where the input is stored. This is the same as the second argument that you usually supply to scanf (well, mostly).

    num is how many characters you want to read, as the documentation says just set it to the length of your respective arrays. This is to ensure that the function does not read more than you can store.

    the third argument is a little more complicated for beginners, and may not be worth explaining to you in your first program. most simply, you want to read from the keyboard, so provide 'stdin' (without the inverted commas) as this argument.


    On another note, statements in C end with a semicolon. return is a C statement.

    I refuse to believe that your compiler is not giving you error messages, please post them and try to interpret them.

  11. #26
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    Im sorry for posting a hope for a quick fix, I was at work and trying to make simple changes to fix my problem. I truly needed to research my second shot a bit more before posting. (Sorry) I truly thank you for your input and will research this while at work. Thank u! Thank u! Thank u!

  12. #27
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31
    Well, you see, if you just took the time to learn how the basic functions on C work, I don't think there'd be any confusion on your part.
    There are many good tutorials for people who are just getting started like you. Read them carefully. Then look at your code and see what's wrong with it.

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