Thread: Chocolate Bannanas

  1. #1
    Unregistered
    Guest

    Talking Chocolate Bannanas

    I think im loosing my mind (Yes im a noob)

    I have been tasked to design a database and have spent the last 3 days at my computer with no Joy

    The database only needs to be read from a pre written text file in this format
    of 10 records

    surname,name,id,date of birth

    Bloggs,Joe,99045678,21-09-79

    I needs a program that cycles from first,last,next and previous

    But also sorts id in chronological order with the first 2 numbers of the id

    so it would go 96,97,98,99,00 so on

    Anyone who can help me would be my hero and I will track them down and buy them a pint!

    Please help

    Desperate!!!!!!!!!!

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    This sounds like homework, as such you are safe with using an array of 10 structs that will hold all of the records.
    Code:
    #define SIZE <some arbitrary number>
    struct
    {
      char lname[SIZE],
           fname[SIZE],
           recId[SIZE],
           dob[SIZE];
    } DB[10];
    Once you read all of the records into the array, you can easily sort it as well as move through it.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Unregistered
    Guest
    Thanx But im a complete noob and although that seems ok I cant really define an array. Well this is my way of thinking

    Surname [7]
    name [7]

    johnson,mark,99876543,21-03-79

    jones,david,99876543,20-04-78

    If the surname is the first 7 then thats fine on line 1

    It reads Johnson

    But then the name will read ,mark,9

    And on the second line the surname will read

    jones,d

    And the name will read avid,99


    Please correct me

    Im so thick I need more Beer

    :-(

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    It sounds like you're reading a certain amount of characters into the array regardless of what they are. This won't do for variable length input. If you'll notice that the record you offered has fields separated by commas, this is what you can use to read the data from the file. Read characters into a member of the structure, when you reach a comma character stop reading and move on to the next member to do the same thing.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Unregistered
    Guest
    What code would you use to make it stiop at comma's cheers

  6. #6
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310

    chocolate covered bananas?

    Maybe I've completely misread all of this, but what signifigance do chocalate covered bananas have to do with ANYTHING!?!

    thanks,

    napKIN

  7. #7
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >I think im loosing my mind

    That explains why this thread was given it's title.

  8. #8
    Unregistered
    Guest
    Got it in one shiro :-)


    Is anyone sure you will see this is related to the first last next and previous thread

  9. #9
    Unregistered
    Guest
    Any Idea's

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    Common isn't obvious whay the title is "Chocolate Bannanas " I'll give you a hint. ....Bjarne is not from Africa....There you go.

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Unregistered
    Any Idea's
    They've already given you ideas. I will NOT do all of your homework for you. I will however give you an outline:

    Code:
    define a structure
    main
        define an array of said structure
        open the file for reading
        do
            read a line using fscanf into one array bucket
            increment your counter
        while counter < total array elements and not at end of file
    
        do whatever...
        close file
        return zero
    That should get you started.

    Quzah.
    Hope is the first step on the road to disappointment.

  12. #12
    Unregistered
    Guest
    Damn im **** at this C stuff

    I just needs a basis to get it to read the individual commas;

    The lecturer said this one was easy but most guys I know are completley confused

    I would love to buy the guy or gal who can help me a nice cool pint.

    Anyway ill keep trying

    cheers

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    fscanf( filenpointer, "%d,%d,%s,%d" &number, &number2, buffer, &number3 );

    Something like that is what you want. Use the same format as above. Read the link on fscanf that I provided above. Consult your book on scanf/printf to see what arguments it takes.

    Quzah.
    Hope is the first step on the road to disappointment.

  14. #14
    Unregistered
    Guest
    So Fscanf reads the data from the file but if a dat file was created with

    bloggs,joe,00456645,23/08.79


    And the comma's represented different fields i.e surname name etc

    How do you make the programme ditinguish different fields

  15. #15
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Unregistered
    So Fscanf reads the data from the file but if a dat file was created with

    bloggs,joe,00456645,23/08.79


    And the comma's represented different fields i.e surname name etc

    How do you make the programme ditinguish different fields
    Do you know how to use printf? You use fscanf the exact same way. When you want to print an integer, you use %d. When you expect to read an integer, you use %d. When a single character, you use %c, and so on.

    Your book (if you have one) should tell you how the specifiers work with printf. They work the same with fscanf.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. So what'd you get?
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 12-28-2001, 06:39 AM