Table of Content

Added test driver to reverse function which comes from K&R C.

#include <stdio.h>
#include <string.h>
void reverse(char s[]);

/* test reverse function */
main()
{
    char s1[] = "This is reverse string test!";

    printf("The original string: ");
    puts(s1);
    printf("\n");
    reverse(s1);
    printf("The reversed string: ");
    puts(s1);
}

/* reverse:  reverse string s in place */
void reverse(char s[])
{
    int c, i, j;
    for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
        c = s[i];
        s[i] = s[j];
        s[j] = c;
    }
}

test result:

$ reverse
The original string: This is reverse string test!

The reversed string: !tset gnirts esrever si sihT