Originally Posted by
Once-ler
j=a jk=ab jkmnop=abd a program that goes through chars and changes them to different chars sometimes with a few digits sometimes with a lot, I need some way of incrementing the correct number of digits
If you don't tell us the general rules (which characters should be incremented by which amounts), we can only guess.
How about using a translation table/array, where you store for each character the new character:
Code:
#include <stdio.h>
int main(void)
{
int translate[256] = {[106] = 97, 98, 99, 100}; // works only in C99 and later
char *test = "jkmnop";
printf("%s = ", test);
for (int i = 0; test[i] != '\0'; i++)
putchar(translate[(unsigned char) test[i]]);
putchar('\n');
return 0;
}
The idea is to use the character as index for the translation array. For example if the character is 'j' (decimal 106 in ASCII), translate['j'] == translate[106] == 97 == 'a'.
You have to do this for every character you want to translate.
Bye, Andreas