Thread: Do my homework

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    2

    Do my homework

    If You Want Something To Do, Try This Exercise...

    Define a human struct that has 3 fields:

    char name[50];
    char gender[10];
    int age;

    Try and use typedef in your program for your struct.

    Write a program that reads in a text file containing names, ages and gender of cartoon characters, which are separated using tabs and each character separated using a new line. For example:

    Homer J Simpson 39 Male
    Marge Simpson 38 Female
    Bart Simpson 10 Male
    Lisa Simpson 8 Female
    Maggie Simpson 1 Female

    You can probably tell, but tab characters separate each field above!
    Read the file a line at a time. Store each person in an array of human structs (you'll need to allocate memory for the array dynamically since you don't know how many characters are defined in the text file).
    Then print out all the original data, stating their name, age and gender.
    Then do the same again but state their ages in 3 years time.
    I know the Simpsons is a bad example as they've been on our screens for over 10 years and don't seemed to have aged at all! By the way, does anyone know how old is Marge??!!
    Last edited by heiroglikano; 05-31-2009 at 03:09 AM.

  2. #2
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    Laughs! That's the funniest post I've ever read. Don't wanna be insulting, but the topic is clearly _against_ our policy.

    Anyway, I have already done it. And you?

    PS: Tab characters are not displayed correctly except when you use [CODE] tags.
    Last edited by Brafil; 05-31-2009 at 04:41 AM.

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by heiroglikano View Post
    If You Want Something To Do, Try This Exercise...

    Define a human struct that has 3 fields:

    char name[50];
    char gender[10];
    int age;

    Try and use typedef in your program for your struct.

    Write a program that reads in a text file containing names, ages and gender of cartoon characters, which are separated using tabs and each character separated using a new line. For example:

    Homer J Simpson 39 Male
    Marge Simpson 38 Female
    Bart Simpson 10 Male
    Lisa Simpson 8 Female
    Maggie Simpson 1 Female

    You can probably tell, but tab characters separate each field above!
    Read the file a line at a time. Store each person in an array of human structs (you'll need to allocate memory for the array dynamically since you don't know how many characters are defined in the text file).
    Then print out all the original data, stating their name, age and gender.
    Then do the same again but state their ages in 3 years time.
    I know the Simpsons is a bad example as they've been on our screens for over 10 years and don't seemed to have aged at all! By the way, does anyone know how old is Marge??!!
    Show some progress and people in this forum will definitely help you.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Well, even I feel this is giving the answer away...

    Read the following man pages,
    * man 3 fgets
    * man 3 malloc / man 3 free
    * man 3 sscanf

    And that's about all you'll need, should take about 10 minutes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 04:39 PM
  2. Homework
    By kermi3 in forum C Programming
    Replies: 10
    Last Post: 09-27-2001, 04:49 PM
  3. Homework
    By kermi3 in forum C++ Programming
    Replies: 15
    Last Post: 09-26-2001, 03:16 PM
  4. Homework
    By kermi3 in forum Windows Programming
    Replies: 5
    Last Post: 09-15-2001, 11:48 AM
  5. Homework
    By kermi3 in forum C Programming
    Replies: 0
    Last Post: 09-10-2001, 01:26 PM