0
I wrote a function that changes the letter of a string by its successor using a pointer of string.
#include <stdio.h>
#include <stdlib.h>
/*
14) Implemente um algoritmo que receba uma string como parâmetro e substitua todas as letras
por suas sucessoras no alfabeto. Por exemplo, a string “Casa” seria alterada para “Dbtb”.
A letra z deve ser substituída pela letra a (e Z por A). Caracteres que não forem letras devem
permanecer inalterados.
*/
void shift_string (char* str)
{
int i = 0;
while (str[i] != 0)
{
if (str[i] == 'z') str[i] = 'a';
else if (str[i] == 'Z') str[i] ='A';
else if (str[i] >= 'a' && str[i] < 'z') str[i]++;
else if (str[i] >= 'A' && str[i] < 'Z') str[i]++;
i++;
}
}
int main() {
char original[10] = {"Casa"};
char shifted[10] = shift_string(original);
printf("%s\n", original);
printf("%s\n", shifted);
return 0;
}
My question is on the function startup shift_string()
in the main()
, because you are giving "Invalid Initializer" error in Dev C++.
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero