Jump to content

'incrementing' a c string

79wjd

I have a string: "aaaaaa" and I'm going to be iterating through every possible combination from "aaaaaa" to "zzzzzz", but I want to do it in chunks.

 

So: (except a chunk size will be too 

aaaaaa + 25 = aaaaaz 

aaaaaa + 26 = aaaaba

aaaaaa + 52 = aaaada

aaaaaa + 500000 = ??????

....

 

except the chunks will be maybe 500,000 and not 52. So short of iterating through it a few thousand times, I'm not really sure how I would go about doing it. 

 

I'm thinking something along the lines of: But I can't figure out the missing step/s to make it work

int addHundredMillions = size / ((int)pow(26.0, 8.0));...int addOnes = size / ((int)pow(26.0, 0.0));  string[0] += addOnes;.... 

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

I might be wrong, but I think you could treat this as a number system.

  • base 2 has {0, 1}
  • base 10 has {0 - 9}
  • base 16 has {0 - 9, A - F}
  • etc

What you have would be base 26 which you can treat as {a - z}. This means your problem is essentially converting between bases (ie: base 10 and base 26).

Ex: What would "bfcza" be in decimal?  (b * 26^4) + (f * 26^3) + (c * 26^2) + (z * 26^1) + (a * 26^0)= (1 * 26^4) + (5 * 26^3) + (2 * 26^2) + (25 * 26^1) + (0 * 26^0)= 456976 + 87880 + 1352 + 650 + 0= 546854
Ex 2: What would 29878 be in base 26?29878 / 26^3 = 1 (truncated)29878 - (1 * 26^3) = 12302So far we have(1 * 26 ^ 3) + 12302Next12302 / 26^2 = 18 (truncated)12302 - (18 * 26^2) = 134Now we have(1 * 26^3) + (18 * 26^2) + 134Next134 / 26^1 = 5 (truncated)134 - (5 * 26^1) = 4Almost done(1 * 26^3) + (18 * 26^2) + (5 * 26^1) + 4Next4 / 26^0 = 44 - (4 * 26^0) = 0Finally(1 * 26^3) + (18 * 26^2) + (5 * 26^1) + (4 * 26^0) = bsfe

And just as binary is often written padded with zeros (ex: 0000 0100), it looks like you'll pad with 'a' (ex: aaaa bsfe).

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×