BorlandC proj

This is a discussion on BorlandC proj within the C Programming forums, part of the General Programming Boards category; what do u mean? 12 is already an integer number! what coversion r u talkin about!? like int number =12;...

  1. #31
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28
    what do u mean? 12 is already an integer number! what coversion r u talkin about!? like int number =12;

  2. #32
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I'd not use the stringID member for each cell struct, Mary. It seems straight-forward to just use the letters for numbers, like Mats suggested.

    Sorry if I confused you, but I was a bit confused myself. I didn't think we'd need a string ID at first, but you convinced me, we would.

    I'm such a push-over sometimes.

  3. #33
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28
    Hey Adak!
    thats ok!
    At least thats the only part u might have got confused about! I'm confused about the whole thing following the calc part!

  4. #34
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by mary18 View Post
    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!
    Actually, A to Z would be 1 - 26 (or 0 to 25! but I'd skip the 0 element here, and start with A = 1, Z = 26, as we all learned in school.

    Mary if you you have a string like:
    AA = 27
    Since AA has two letters, it's > 26. Second A tell you it's one greater than 26.

    The first A is in the "26's" column, see?

    AB = 28
    We have A 26's, so 1 * 26, plus B one's, so 26 + 2 = 27
    ...
    AZ = 52

    BA = 53
    Since BA has two letters, it's > 26. How much greater? Well, we have "B" 26's, so 2 * 26, for the B, and then 1 more for the A.

    It's just like base 10:

    10's column,| 1's column

    except it's base 26:

    26's column,| 1's column

    That's what you meant, right Mats? (I'm sure it is!)
    Last edited by Adak; 01-14-2008 at 09:33 AM.

  5. #35
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    -

    ok, I see the point now!
    how about this? like the ascii code for A through Z is 65 through 90 right?
    so if we have a single letter like A thru Z, then we'd do: ascii code of that letter minus 65. so if its A, then 65-65=0,..., if Z, 90-65 is 25! and the difference gets returned!
    then if its a two letter one like AA thru ZZ, we'd get the ascii code of the first letter minus 65 plus 26. so if its AA it'd be asciiCodeOfA= 65-65+26=26
    if its ZZ => 90-65+26=51
    do u think this'll work too?

  6. #36
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That's what I meant. And you can actually use A=1 all the way through.
    Just remember that C arrays start at zero, so A1 is actually cell [0][0], and C9 is [2][8] for example. So you need to (at the point where you access the array, at least) subtract one from each of the Y and X indices of the array.

    --
    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.

  7. #37
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Lots of times I do that (subtract the indicies), but in this case, I would not advise it.

    Just too easy to let the zero'th element, go unused. No more problem! Everything matches up with
    what you're seeing on-screen, with the row numbers, and what you learned in elementary with the alphabet.

    Guess I'm old-fashioned too, sometimes.

  8. #38
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Actually, as long as you don't have HUGE amounts of columns and rows, it makes little difference indeed, and it does clearly make the code more simple.

    Mary: Forget my idea of subtracting one. Just use A1 as [1][1] and C9 as [3][9] - it's far easier.

    --
    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.

  9. #39
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28

    -

    ok now how do we split the letter from the number part, in like AB34?? there should be some str.. predefined funct for that! I was gonna use strtok, but as the sec arg it needs a delimiter and I can not find a delimiter in AB34!
    there's also strcspn working this way:
    char str[] = "AB45";
    char keys[] = "1234567890";
    int i;
    i = strcspn (str,keys);

    and it'll return 3 as the location of the first dig in str[] thats contained in keys too! but thats of no help either cuz it can't split the two!
    any other func u guys know of?

  10. #40
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by mary18 View Post
    ok now how do we split the letter from the number part, in like AB34?? there should be some str.. predefined funct for that! I was gonna use strtok, but as the sec arg it needs a delimiter and I can not find a delimiter in AB34!
    there's also strcspn working this way:
    char str[] = "AB45";
    char keys[] = "1234567890";
    int i;
    i = strcspn (str,keys);

    and it'll return 3 as the location of the first dig in str[] thats contained in keys too! but thats of no help either cuz it can't split the two!
    any other func u guys know of?
    First, I would like to backtrack just a bit on the A = 1, Z= 26 thing. We need A = 0, so we have a placeholder number in our base 26 system. So NEW and improved: (and damninumm that Mats ):

    A = 0, Z = 25. I still wouldn't use row 0, however.

    Now onward and upward.

    In hexadecimal (base 16), the numbers are: 0 - 9, then A,B,C,D,E,F. IOW's the letters in hex ARE numbers. In base 26, which you'll use, ALL the letters are numbers, and indicate columns of the spreadsheet. The rows of the spreadsheet, are still in base 10.

    I don't know a pre-defined function for separating them. We'll have to roll our own, I believe.
    Something like:

    Code:
    int column number
    char column string[6] /* holds five letter places we'll use 1-5 */
    
    /* Get the column string */
    while(char is not a digit)  {
       column string num++
    }
    /* Change it to a base 10 number */
    
    for(i = column string num, column flag = 1; i > 0; column flag++, i--)  {
       if(column flag == 1)  /* in the 1's column
          column number += column string[i] - 'A' /* A now is 0 */
       
       if(column flag == 2)  /* 26's column now */
          column number += (column string[i] - 'A') * 26 /* A is now 26 */
      
       if(column flag ==3)  /* 676's column now */
          column number += (column string[i] - 'A') * 676 /* A now represents 676 */
    
       /* expand as needed, but next column is 17576! */
    
    
    }
    The above is off the cuff, and completely untested. Just to show the idea, without using pseudo code.

    Another way to do the change to base 10 loop, is to reverse the columns letters before finding their base 10 value. I didn't use that here, however.

  11. #41
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28
    O.K. Adak, I see the point! thanks alot for ur reply!
    by the way seems like u're kinda interested in the A to Z thing! huh?!

  12. #42
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I see that A-Z thing as a significant hurdle for your program. I've used base 16 before for a matrix, but not base 26. Had to kick out some cobwebs.

    Now that we see that A=0 is needed, the code for things like:

    Code:
    for(i = whatever; i < something; i++)
       more code here;
    
    will need to be adjusted in some cases to:
    for(i = whatever - 1; i < something; i++)
    Stuff like that.

  13. #43
    Registered User
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    28
    yeah I know, this A to Z part has one of the key roles of my prog!
    but I think I finally got it working properly!
    Now do u guys know how to free a memory allocation done for a 2D array?!
    like for malloc'ing a 2D array of ints, size m x n we'd do this:

    int** 2DArray = (int**) malloc (m * sizeof(int*));
    for (int i = 0; i < m ; i++ )
    2DArray[i] = (int*) malloc (n * sizeof (int));

    so for freeing it, do we have to do somethin like this:

    for (int i = 0; i < m ; i++ )
    free(2Darray[i]);

    does that look all right?!?

  14. #44
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mary18 View Post
    yeah I know, this A to Z part has one of the key roles of my prog!
    but I think I finally got it working properly!
    Now do u guys know how to free a memory allocation done for a 2D array?!
    like for malloc'ing a 2D array of ints, size m x n we'd do this:

    int** 2DArray = (int**) malloc (m * sizeof(int*));
    for (int i = 0; i < m ; i++ )
    2DArray[i] = (int*) malloc (n * sizeof (int));

    so for freeing it, do we have to do somethin like this:

    for (int i = 0; i < m ; i++ )
    free(2Darray[i]);

    does that look all right?!?
    You also need to free the actual 2D array itself.

    --
    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.

  15. #45
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > does that look all right?!?
    You also need
    free( 2Darray );

    I assume this is pseudo-code, since 2Darray isn't a valid identifier.

    Also, drop the cast on the return result of malloc. The FAQ explains why such a thing is unnecessary.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 3 of 5 FirstFirst 12345 LastLast
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, 11:57 AM
  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, 07: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

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