Quick question arrays/pointers

This is a discussion on Quick question arrays/pointers within the C Programming forums, part of the General Programming Boards category; First off: I'm not asking anyone to do any programming for me Just as simple an answer as you can ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    8

    Quick question arrays/pointers

    First off: I'm not asking anyone to do any programming for me

    Just as simple an answer as you can give that answers the question as I'd like to do the work/figure most of it out on my own.

    Quick prompt:

    Write a program which generates interactive stories. You
    program should begin by asking the user a number of questions such as: what is your name? How old are you? What is your favorite color? Etc. After obtaining a sufficient amount of personal information your program should output a short story which incorporates user’s personal information you have obtained via questioning. The generated story should be somewhat different if the program is run a few times (randomly generate alternative endings, randomly select different descriptions of objects (blue car, green car, red car), etc. Your program should make use of pointers and arrays to deal with strings.

    Sample Output:
    What is your name? Roman
    How old are you? 29
    What is your favorite color? black
    Roman is a 29 year old who likes his black laptop…

    Sample Output (second run of the same program):
    What is your name? Roman
    How old are you? 29
    What is your favorite color? black
    Roman is a 29 year old who likes his black Toyota Corolla...


    The one thing I'm a bit held up on is how to make the paragraph generate random events/descriptions/etc. Obviously I need to use arrays/pointers, but I'm not exactly sure what to use and the logic behind it.

    Any bit of help or minor pointing in the right direction would be great. Give me some direction and I'll hunt it down/work it out myself. I know it's relatively easy, I'm just not grasping it so...

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Have you looked at rand()?

  3. #3
    Registered User
    Join Date
    Aug 2008
    Posts
    67
    Create an array that holds the "alternate endings." Look at rand(), as previously stated by tabstop, and use the returned number to choose the array index.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    8
    I lied

    Read through my C book on arrays and couldn't quite find a way to store multiple values in a single array.

    Would it just be something like

    Code:
    cRandomColor[4] = {blue, red, green};

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    Arrays are simply collections of values which are accessible via a numeric index. Sure arrays hold multiple values... that's what they do best.

    Maybe something like the following:
    Code:
    char *cRandomColor[4] = {"blue" , "red" , "green", "yellow" };

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I also lied, liljp617. I don't really know how to program... I just copied off of my neighbor in programming class

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21