I have exercise to use for loop to initialization 1 string array from A to Z and then Z to A.
I was successful to print from A to Z but print Z to A not working. So i need to help in this code.
char *problem58()
{
char temp, *result = (char *)malloc(52 * sizeof(char));
int left = 0, right = 52 - 1;
for (char i = 'A'; i <= 'Z'; i++)
{
result[left] = i;
printf("%c", i);
left++;
}
// this is my idea to reverse this string
for (int i = left; i < right; i++)
{
temp = result[left];
result[left] = result[right];
result[right] = temp;
printf("%c", result[right]);
right--;
}
return result;
}
line code run in terminal: ABCDEFGHIJKLMNOPQRSTUVWXYZSW\:C=cepSmoC