I'm trying to add an int to each char in a char array but I don't know how to do that.
void Offset(char sirDeCaractere[100], int x)
{
int i = 0;
while (sirDeCaractere[i] != '\0')
{
sirDeCaractere[i] += x;
i++;
}
printf("%c", sirDeCaractere[i]);
}
I've been trying to do something like this for a while, but I can't figure it out. Written like this I don't think it will work due to pointer arithmetic, but I have no other ideas.
For example:
Input:
sirDeCaractere = cuvant
x = 5
Output:
hz{fsy
How should I edit my code in order to achieve the desired output?
Right now my program is crashing (as I said, because sirDeCaractere[i] += x; is pointer arithmetic).
Thanks.