I am working on a small encryption algorithm that does this:
converting:
input = 356307042441013 to output = 333536333037303432343431303133
and it works like this: if a number is equal to 3 , it changes it with 333 except if it is in the last position of the string. if not, we add 3 between every two numbers that are different from 3
input = 3 5 6 3 0 7 0 4 2 4 4 1 0 1 3
to
output = 333 5 3 6 333 0 3 7 3 0 3 4 3 2 3 4 3 4 3 1 3 0 3 1 3 3
to do so, I wrote this code:
int main() {
const char *imei = "362162356836934568";
char *imei_buffer;
strcpy(imei_buffer,'\0');
int i = 0;
while (i < strlen(imei))
{
if (i <= (strlen(imei) - 1))
{
if (imei[i] == '3')
{
strcat(imei_buffer, "333");
}
else if ((imei[i] != '3') && (imei[i + 1] == '3'))
{
strcat(imei_buffer, &imei[i]);
//strcat(imei_buffer,'3');
}
else if ((imei[i] != '3') && (imei[i + 1] != '3'))
{
strcat(imei_buffer, &imei[i]);
strcat(imei_buffer, "3");
}
}
else if (i == strlen(imei))
{
if (imei[i] == '3')
{
strcat(imei_buffer, "333");
}
else if (imei[i] != '3')
{
else if (i == strlen(imei))
{
strcat(imei_buffer, &imei[i]);
//strcat(imei_buffer,'3');
}
i++;
}
printf("imei_buffer : %s",imei_buffer);
return 0;
}
The code executes with no error, but it shows no result at the end.
Where I could have gone wrong in this implementation ?