Thread: Hello :D

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    3

    Hello :D

    Hello I've joined (after using this for some REALLY random things) because I've thought I may try really making something like a game/semi large program. (I'm still really new to this... so..) I'm not trying anything too hard, Its just a text game, anyways heres the code.
    Code:
    int main() // The First room
    {
        char *Op;   // The whole Operation for the First part of the game
        bool FirstRoom;  // First room
        char *yourName;
    
        FirstRoom = false;
    
        printf ("Please Input your name (Up to 32 Characters):\n");  // Inputing your name
        scanf ("%c", yourName);
    
        printf ("I'm stuck in a small building... I see no way of getting out. But I need to anyways.\n");  // Opening dialogue
        
        while ( FirstRoom == false || Op == look at room || Op == examine room)
        {
    	printf("\nI see some spoons and something red half buried in the ground, One part of the wall is reenforced wood... no way to brake thru.\n");
    	scanf("%c", Op);
        if (Op == look at wood || examine wood || look at wood wall || examine wood wall)
        {
    	printf("\nIts been nailed down tight... I'd have to have explosves to get thru it...\n");
    	scanf("%c", Op);
        }
        else if (Op == tackle wood || attack wood || kick wood || tackle wood wall || attack wood wall || kick wood wall)
        {
    	printf("\nI get up the guts (or stupidty) to attack the reenforced wood... Ramming it with all my might. I hear a Thud! then a Crack! I look up... just to see I stepped in something on the floor.\n");
    	scanf("%c", Op);
        }
        else if (Op == look at spoons || examine spoons)
        {
    	printf("\nThere... spoons.. What else do you want me to say?\n");
    	scanf("%c", Op);
        }
        else if (Op == look at red || examine red || look at red thing || examine red thing)
        {
    	printf("\nI can't tell what it is... I don't really want to mess with it due to I might need it...\n");
    	scanf("%c", Op);
        }
        else if (Op == dig up red || dig up red thing)
        {
    	printf("\nThe ground is WAY to hard for my hands to dig it up...\n");
    	scanf("%c", Op);
        }
        else if (Op == pull up red || pull up red thing || pick up red || pick up red thing)
        {
    	printf("\nI don't want to try... I may damage whatever it is, and I may need it.\n");
    	scanf("%c", Op);
        }
        else if (Op == take spoons || pick up spoons || grab spoons || get spoons)
        {
    	printf("\nI took the spoons... WoW.. arnt I great..\n");
    	scanf("%c", Op);
        }
        else
        {
          printf("\nI'm sorry I either don't understand what you want me to do or your just making no since... (I'm not perfect...)\n");
          scanf("%c", Op);
        }
    
        return 0;
    }
    I know it has something to do with the way that I'm trying to do the Op but I'm not sure if I'll need to make int for all of them or if there's an easier way to do this.

    Thanks
    Noyesdude

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Code:
    if (Op == look at wood || examine wood || look at wood wall || examine wood wall)
    There are several examples of that type of thing in your code. You cannot compare strings that way. Look up the strcmp function.

    Also, turn the warnings on for your compiler. You would be able to see that you are missing a brace to finish a while loop.
    Last edited by kermit; 09-19-2009 at 06:20 PM.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    test.c: In function ‘main’:
    test.c:6: error: ‘bool’ undeclared (first use in this function)
    test.c:6: error: (Each undeclared identifier is reported only once
    test.c:6: error: for each function it appears in.)
    test.c:6: error: expected ‘;’ before ‘FirstRoom’
    test.c:9: error: ‘FirstRoom’ undeclared (first use in this function)
    test.c:9: error: ‘false’ undeclared (first use in this function)
    test.c:16: error: ‘look’ undeclared (first use in this function)
    test.c:16: error: expected ‘)’ before ‘at’
    test.c:20: error: expected ‘)’ before ‘at’
    test.c:25: error: ‘tackle’ undeclared (first use in this function)
    test.c:25: error: expected ‘)’ before ‘wood’
    test.c:30: error: expected ‘)’ before ‘at’
    test.c:35: error: expected ‘)’ before ‘at’
    test.c:40: error: ‘dig’ undeclared (first use in this function)
    test.c:40: error: expected ‘)’ before ‘up’
    test.c:45: error: ‘pull’ undeclared (first use in this function)
    test.c:45: error: expected ‘)’ before ‘up’
    test.c:50: error: ‘take’ undeclared (first use in this function)
    test.c:50: error: expected ‘)’ before ‘spoons’
    test.c:62: error: expected declaration or statement at end of input
    Interesting, Noyesdude, but you are off to a rather bad start. I do not know where to begin "correcting" the mess, beyond being blunt and telling you the whole thing is almost certainly going in the garbage. Except for your dialogue, etc, which you can save for when you figure out how to make this work, because you are not even close here.

    My advice:
    1. DO NOT WRITE MORE THAN 3 LINES OF CODE WITHOUT TEST COMPILING.
    2. You need to do some basic tutorials or excercises on the C programming language.
    3. A char is only one letter; a char pointer without allocated memory is no characters at all.


    What you want to do is actually not that hard, I think it is a good idea for a beginner project, but AFAICT you probably have not done anything else in C yet. Doing little tutorials on arrays, pointers, and control loops may seem less than exciting, but there really is no way around them. By trying to implement a "grand idea" first, you are only making the learning process more difficult.

    I am not a mean person. This forum is generally a great place to get advice. Google around for some intro C programming tutorials, try to compile and execute small programs (say 5-10 lines) and if you have problems or questions, come back and ask.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    Thanks. I won't even try with that code any more then (I'm sure I should be really thanking you on all the time you've saved me trying to work out some of thos problems. So Thanks for that) I've been messing around with online tutorials but none of them really touched much on thos subjects.
    I'll look for that in specific and see what I come up with. (Do any of you have anything you might recommend as far as tutorials go?)

    and there's no way I could think of you as a mean person. as I said up there I'm sure you just saved me lots of time trying to help a lost cause.

    Thanks
    Noyesdude

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by Noyesdude View Post
    Thanks. I won't even try with that code any more then (I'm sure I should be really thanking you on all the time you've saved me trying to work out some of thos problems. So Thanks for that) I've been messing around with online tutorials but none of them really touched much on thos subjects.
    I'll look for that in specific and see what I come up with. (Do any of you have anything you might recommend as far as tutorials go?)

    and there's no way I could think of you as a mean person. as I said up there I'm sure you just saved me lots of time trying to help a lost cause.

    Thanks
    Noyesdude
    I can't recommend any good tutorials, personally (though I'm certain they exist), but at the very least you can always look through any and all that you can find just to get the gist of things. I prefer using a book, myself, and started with "C, a Software Engineering Approach", which, although perhaps somewhat outdated now, was an excellent primer. The main idea, though, is to go through whatever materials you can get a hold of as much as necessary to get a firm grasp on the subject, before writing a single line of code.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Noyesdude View Post
    I've been messing around with online tutorials but none of them really touched much on thos subjects.
    I'll look for that in specific and see what I come up with. (Do any of you have anything you might recommend as far as tutorials go?)
    I generally don't, because there is a lot of decent stuff around and I think people are better off choosing stuff that is appealing and comprehensible to them.

    However, my first thought was you need to understand what a string is, and after googling "C string tutorial" I was a little disappointed. And to understand what a string is, you may need to understand arrays first.

    Really, you need to do a few chapters from a book. The closest thing I could find was this:

    A Tutorial on Pointers and Arrays in C

    which is ostensibly about "pointers", but they are pretty central to the whole thing, and it is clear and in depth.

    If you are using gcc or linux, this is great:

    The GNU C Programming Tutorial

    In general, if you are looking around for material, be aware that there is a difference between C & C++ and you need to avoid stuff that involves the later (unless you want to learn C++).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    3
    @MK27 Thank you very much I'll look both of thos and see if I can get a better grasp on what I need. ( I'm using both Linux(Ubuntu really but mainly same thing) and windows. But mainly my linux )

    @Sebastiani Yes I like books over online tutorials also but I don't really have $30-$50 to spend right now... So I'll have to stick with what I can get my hands on

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by Noyesdude View Post
    @MK27 Thank you very much I'll look both of thos and see if I can get a better grasp on what I need. ( I'm using both Linux(Ubuntu really but mainly same thing) and windows. But mainly my linux )

    @Sebastiani Yes I like books over online tutorials also but I don't really have $30-$50 to spend right now... So I'll have to stick with what I can get my hands on
    Understandable. In that case you might check out your local library and discount book stores (which is where I found the aforementioned text).

    Anyway, tutorials are fine, too.

  9. #9
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Steve Summit has some tutorial(ish) type material online here. His Introductory C Programming Class Notes might be the one you want to start with. He also has some notes to go along with Kernighan & Ritchie's The C Programming Language which are a good supplement for the text (which can be terse). If you manage to get your hands on a copy of that book (at the library or whatever), you can follow along with his notes. Richard Heathfield also maintains a site with volunteer submitted answers to the exercises (you can find that with a web search if you are interested).
    Last edited by kermit; 09-19-2009 at 07:20 PM.

Popular pages Recent additions subscribe to a feed