/* MCS 507 L-8 Fri 27 Jan 2022 : revertString.c */
 
/* This program prepares a general template to
 * extend Python with a C program.
 * We pass a string to a C function.
 * The C function reverts the characters. */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int passString ( int n, char *s );
/*
 * Takes the n characters in the string s
 * and reverts the characters in the string. */

int main ( int argc, char *argv[] );
/*
 * Prompts for the length of the string 
 * and a string of characters.
 * Prints the input and output of
 * the function passString. */

int main ( int argc, char *argv[] )
{
   int n;
   char *s;

   printf("give length n : ");
   scanf("%d",&n);
   s = (char*)calloc(n,sizeof(char));
   printf("give a string : ");
   scanf("%s",s);
   n = strlen(s);

   printf(" input string : %s\n",s); 
   passString(n,s);
   printf("output string : %s\n",s); 

   return 0;
}

int passString ( int n, char *s )
{
   int i;
   char buffer;

   for(i=0; i<n/2; i++)
   {
      buffer = s[i];
      s[i] = s[n-1-i];
      s[n-1-i] = buffer;
   }
   return 0;
}
