reverse_string_stdio.c - Inputs a string using scanf, outputs the reverse

 
#include "pic24_all.h"
#include <stdio.h>

void reverseString(char *psz_s1, char *psz_s2) {
  char *psz_s1end;
  if (!(*psz_s1)) {
    *psz_s2 = 0;  //psz_s1 is empty, return.
    return;
  }
  psz_s1end = psz_s1;
  //find end of first string
  while (*psz_s1end) psz_s1end++;
  psz_s1end--;      //backup one to first non-zero byte
  //now copy to S2 in reverse order
  while (psz_s1end != psz_s1) {
    *psz_s2 = *psz_s1end;
    psz_s1end--;
    psz_s2++;
  }
  //copy last byte
  *psz_s2 = *psz_s1end;
  psz_s2++;
  //mark end of string
  *psz_s2 = 0;
}


#define BUFSIZE 63
char  sz_1[BUFSIZE+1];
char  sz_2[BUFSIZE+1];
int main (void) {
  configBasic(HELLO_MSG);
  while (1) {
    scanf("%s",sz_1);          //get a string from the console
    reverseString(sz_1, sz_2);
    printf("%s\n", sz_2);      //output the reversed string
  }
}