Write the REVERSE function which reverses the character order of a string.
Difficulty level

Video recording
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
int length(char str[])
{
int i = 0;
while (str[i])
i++;
return i;
}
void REVERSE(char str[])
{
int I, J;
char aux;
J = length(str) - 1;
for (I = 0; I < J; I++, J--)
{
aux = str[I];
str[I] = str[J];
str[J] = aux;
}
}
void main()
{
char str[100];
printf("Enter a string: ");
gets(str);
REVERSE(str);
puts(str);
getch();
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
