Flip a string in its own char array: i points at the first character, j at the last; swap them, then move both toward the middle. abcde becomes edcba. Note: char a[] = "abcde" is an array you can change; the string that char *p = "abcde" points to can't be changed. Finish reverse(s); it shows two flipped strings.
edcba dc21BA
#include <stdio.h>
#include <string.h>
void reverse(char s[]) {
int i = 0;
int j = 0;
// your code here: make j point at the last character
while (i < j) {
// your code here: swap s[i] and s[j]
i++;
j--;
}
}
int main(void) {
char a[] = "abcde";
char b[] = "AB12cd";
reverse(a);
reverse(b);
printf("%s\n", a);
printf("%s\n", b);
return 0;
}
Run tries the examples. When they look right, Submit.