Thread: BorlandC proj

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Don't stop de-bugging the calculator part! That's the heart of the whole program. Finish it, and THEN let's see what else might be next to do.

    You might keep the column headers in an array of strings. No particular need to use them internally in your program that I can see.

  2. #17
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    -

    Hi,
    yes I know thats the core of the whole prgm but I've checked it out for many cases and it still seems to be working!
    jus one more thing about the calc part, as Mats had pointed out before, its not a good thing to have no condition-checking for the case of operands and blindly saying that if the input is none of ops so its an operand(thats what I've done). I was thinking of figuring out a condition for the case of operands but I didn't get anywhere! I was gonna use the ascii codes but that wasn't a good idea; then I thought of the lib func isDigit but that will only work for 1dig numbers! do u have any suggestions?
    and also I am trying to write a function that given the characteristic of a cell as an operand, like AB57, it will return the num of rows and cols, so using these two, we can trace that cell in our 2D array and get the content and replace it in the expression instead of AB57! so like for AB57 it will return row 57 and column 28 I guess! do have any suggestions as to how to write such a function?(its getting AB57 as an string)

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So for your variable store, you need two things:
    1. A management function to allocate/track what cells you have.
    2. A function that takes a reference to a cell and returns the contents.

    You probably will need some more functions as helpers, so I would start a new C file called "cells.c" or some such, just to keep the code nice and tidy. If you don't split it early on, it's likely to lead to more work when you DO find that you HAVE to split it later on. Unless you go completely silly, it's better to have many small files than to have a few large ones. Obviously, the splits should be done at some logical levels, such as one file that handles expressions/calculations, another that handles cells, and so on.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I would use an array of structs for this project. The "str" portion of that cells struct, would have the string ID or name, for that cell.

    If you don't group your data together, for each cell of the array, it could be a real logical nightmare, imo.

    I would use the ascii codes to determine what input is and is not, a valid number for input. If a char is >= ascii value of '0' && <= ascii value of '9', then doesn't it have to be a number?

  5. #20
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Adak View Post
    I would use an array of structs for this project. The "str" portion of that cells struct, would have the string ID or name, for that cell.

    If you don't group your data together, for each cell of the array, it could be a real logical nightmare, imo.
    I completely agree - the content of a cell should [probably] be stored as a struct.

    I would use the ascii codes to determine what input is and is not, a valid number for input. If a char is >= ascii value of '0' && <= ascii value of '9', then doesn't it have to be a number?
    If we assume that the "number" is an integer, then yes.. Floating point (which I think eventually will have to be introduced in this project) could also start with "." (as in .1 or .0001). Numbers can also start with '-' for negative numbers.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #21
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    instead of using acsii codes you can call a function isdigit for the same purpose
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  7. #22
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    -

    ok yeah, I am goin to use a struct for each cell! but still the stringID part of it needs to be defined, using the function I talked about before!
    as Mats said "A management function to allocate/track what cells it is" is what I need too! and I need some suggestions for how to write such func that looking at the string ID like AB57 would return 57 and 28 as num of rows and cols to track that cell?

    and about the suggestions for checking a num, well first of all as Mats said, my oprnds are of type float!
    and also both the case Adak suggested, (char is >= ascii value of '0' && <= ascii value of '9'), as well as the idea of Vart,both of which I had thought of before, wouldn't these only work if the num is a single digit one? I mean what if we have entered 12, 57, 109,..as operand? then how to use ascii codes or isDigit lib func for these cases?

  8. #23
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The string ID can be another member of the cell's struct. Isn't that easiest and most logical?

    I believe every char in your input is going to have to be checked, one by one, anyway. 127 is going to have it's 1 checked, then the 2, and finally the 7. So why not use isdigit for that?

    You'll have enough to keep you busy with other needed code, don't worry!

    Yes, of course you should go with floats or doubles, where needed.

  9. #24
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So what part of "translating An (where A is one or more a letters 'A'..'Z' and n is one or more digits 0..9)" into a number are you having problems with? By the way, it may be better to translate it to a "Y, X" coordinate pair, rather than one integer value [you can combine them later].

    There is a function called "isdigit" in type.h, which will tell you if a char is a digit or not - that is '0'..'9'. To check that something is a valid floating point number is more complex, as they can contain other things - easiest is probably to extract the operand as a string, then use strtod() to convert the string, and check both the return value and the "where we stopped" pointer, to see if ALL of the string got accepted by strtod() - I would recommend writing a tiny program that takes a user-input string and runs it through your conversion routine, so that you can check that on it's own - it's important to get it right!


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #25
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28
    ok Adak, so u mean instead of tracking the cell using the row & col num, we simply compare the ID we have with the ID of each cell and see which one matches???
    yes, I know there's alot more to do and I'm not left with that much time!
    and about isDigit, ok I think I got it, I have to try what Mats suggested though! but thanx for ur replies!
    So whats ur suggestions for the next thing I have to do now that the calc part is done?

  11. #26
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Seeing as you still HAVE to convert the number, I think my suggestion is "better", since the "strtod" (or strtol for integers) do all the checking you will ever want, instead of "you" doing some checking and then passing it to strtod() to do more checking.

    And just to make sure, it's NOT "isDigit", but "isdigit".

    I suggest you start working on the cell-structure, storing and retrieving cell contents to start with, and then integrating your calculator to use the retrieval functions to reference cells.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #27
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28
    oh and for Adak's idea, how is each cell assigned an ID like AB45 ? and also how do we convert the alhpabetical col into its value so like AB to 28?!

  13. #28
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mary18 View Post
    oh and for Adak's idea, how is each cell assigned an ID like AB45 ? and also how do we convert the alhpabetical col into its value so like AB to 28?!
    In Adak's suggestion, I suppose you just store cells in a [large] array, and just read through the list until you either find one that matches or the end of the array. I'm not sure how well that would work tho', as you probably still need to track how large your 2 dimensions are of your "active data".

    But it's actually not very hard to translate the values from string to "two numbers". Think about it:
    A = 0,
    B = 1,
    ...
    Z = 26
    AA = 27
    AB = 28
    ...
    AZ = 51
    BA = 52
    BB = 53
    ...

    Do you see something you can use in that?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #29
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28
    Mats, unfortunately I can't see anything! like A to Z is 0 to 26, and then the next 26 would be AA to AZ and so on! but I can't figure out a loop for that! like we can't go by comparing what we have with each letter, like if its A then its 0 if B then its 1... uh.. I know it sounds so simple as it should be but I can't figure it out!

  15. #30
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So how do you convert a number (e.g "12") into an integer value of 12?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fullscreen .exe window in Borlandc
    By mihaio07 in forum C Programming
    Replies: 3
    Last Post: 01-29-2008, 12:57 PM
  2. export vc++ proj to dev c++
    By jay_uccs in forum C++ Programming
    Replies: 1
    Last Post: 06-26-2005, 07:43 AM
  3. Need Help on creating a Proj on Dev C++
    By djxtremor in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2002, 08:24 PM
  4. Simple problem for you guys - school proj
    By ryancsutton in forum C++ Programming
    Replies: 7
    Last Post: 10-01-2002, 03:06 PM