Thread: Structures, Arrays, Sums...

  1. #1
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140

    Unhappy Structures, Arrays, Sums...

    I was wondering if any one could help, point me in the right direction or offer any advice with my problem. The position within the file of the record is decided by this algorithm

    result = data->vehicle_reg[0] - 'A';
    /*First letter of the registration minus the int value of A */
    position = (result *1000)+ data->vehicle_reg[1,2,3];
    /*Result of first part mutiplied by 1000 and with the first
    three digits of the registration added*/

    So, for example
    A122FFF would lead to the result of: 122

    Data is a pointer to a structure, (I think) it's declared as below:-

    struct car
    {
    vehicle_reg
    etc.
    } data;

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You need to give more information to go on. How exactly does this translate to where in the file this records is stored? What position in the file does your example fall into, and why?

    You need to provide more information. How many records are there total? Can they be added on a whim and if so, will they be automaticly sorted into the "correct" position in the file, updating all others? There is not enough to go on.

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

  3. #3
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140
    The 'position' generated is the files position, and where it will be written to, it's a random access file (Txt) and will contain 26000 records in total. The records are added only afte checking that a record does not exsist at the positon generated, if so the program will look for places after, the number...

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > it's a random access file (Txt) and will contain 26000 records in
    > total.

    Ug. That's horrible.

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

  5. #5
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140
    Indeed...

    So, can anyone help?

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Don't mind helping, but the description of the algorithm is currently quite fuzzy, could you elaborate?
    Callou collei we'll code the way
    Of prime numbers and pings!

  7. #7
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140

    Post

    The algorithm is as follows:

    The algortihm will take the integer value of the first character (of the registration), and subtract the integer character of 'A' from it and then multiply the result by 100. The next three digits are added to to give the record number.

    For example "A122GFD"

    'A' - 'A' = 0;
    /*First letter of the registration minus the integer vaule of A*/

    (0*1000) + 122 = 122
    /*0 is the answer from the first part of algorithm, and the number 123 comes from the first three number of the registraion*/

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Starting from
    char vehicle_reg[4];

    Which contains say
    "A123"

    Then it's
    Code:
    result = (vehicle_reg[0] - 'A') * 1000 +  
             (vehicle_reg[1] - '0') * 100 + 
             (vehicle_reg[2] - '0') * 10 + 
             (vehicle_reg[3] - '0') * 1;

  9. #9
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140

    Smile

    Why thank you good Sir....

    May you're jelly never fail to set properly...

  10. #10
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    ^--I think you ment jello, jelly doesn't really "set"

  11. #11
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    603
    Excellent.

    A flame war about Jello / Jelly.

    ::Sits back in chair with cold beer::
    Visit entropysink.com - It's what your PC is made for!

  12. #12
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140
    Never had jello... Had jelly... it sets in a way... starts as liquid, then gets to that wobbly 'set' phase...

    But... If you're going to be so picky...

    May you're toast always land butter side up....

  13. #13
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    *sits next to rob and passes the popcorn*
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  14. #14
    Registered User
    Join Date
    Feb 2002
    Posts
    589
    I hate Jello. specially the green Jello. People that eat Jello should all die. Why can't everyone understand that the blue Jelly is about 1000 times better. I rather eat worms then Jello.
    Hey whos that?, on the chair drinking beer and eating popcorn?
    Last edited by Barjor; 04-19-2002 at 12:27 PM.

  15. #15
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Barjor
    I hate Jello. specially the green Jello. People that eat Jello should all die. Why can't everyone understand that the blue Jelly is about 1000 times better. I rather eat worms then Jello.
    Hey whos that?, on the chair drinking beer and eating popcorn?
    Yeah. Jello is rather nasty. After all, it's made from the bones of horses which have been processed with acid. Just look up what gelatin is made from...

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-09-2009, 11:06 AM
  2. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  3. returning arrays of structures
    By manolo21 in forum C Programming
    Replies: 2
    Last Post: 03-31-2003, 08:09 AM
  4. errors with arrays and structures
    By ssjnamek in forum C++ Programming
    Replies: 4
    Last Post: 03-03-2002, 11:48 PM
  5. Newbie Help (Arrays, Structures, Functions,Pointers)
    By tegwin in forum C++ Programming
    Replies: 3
    Last Post: 02-19-2002, 06:29 PM