what do u mean? 12 is already an integer number! what coversion r u talkin about!? like int number =12;
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;...
what do u mean? 12 is already an integer number! what coversion r u talkin about!? like int number =12;
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.
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!
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 10:33 AM.
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?
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.
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.
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.
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:
The above is off the cuff, and completely untested. Just to show the idea, without using pseudo code.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! */ }
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.
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?!
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:
Stuff like that.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++)
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?!?
> 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.