// VC++ 6.0
#include <stdio.h>
 
/*
    helper function
    could be merged into the rev_string()
*/
void rev(char *pszString, int nFrom, int nTo)
{
    while(nFrom < nTo)
    {
        char c = pszString[nFrom];
        pszString[nFrom++] = pszString[--nTo];
        pszString[nTo] = c;
    }
}
 
/*
    rev_string()
    will first reverse the full text string given
    before traversing and reversing the words within.
*/
void rev_string(char *pszString)
{
    int i = 0, j = 0;
 
    /* 
        Get string length, without including the terminator
    */
    int nLen = 0;
    while(pszString[++nLen]);
 
    /*
        Reverse the whole text string
    */
    rev(pszString, 0, nLen);
 
    /*
        Reverse each word in the reversed sentence
    */
    while(i <= nLen)
    {
        if(pszString[i] == 0x20 || pszString[i] == 0x00)
        {
            rev(pszString, j, i);
            j = ++i;
        }
        else { i++; }
    }
}
 
int main()
{
    char szText[] = "this is a test string";
 
    rev_string(szText);
 
    printf("%s\n", szText);
    return 0;
}