/* File: acronym.c

   Implements and tests the Acronym function.
*/

#include<stdio.h>
#include"genlib.h"
#include"simpio.h"
#include"strlib.h"

/* Function Prototypes */
string Acronym(string str) ;

main() {
   string str ;

   printf("This program generates acronyms.\n") ;
   printf("End the program by entering a blank line.\n") ;
   while (TRUE) {
      printf("String: ") ;
      str = GetLine() ;
      if ( StringEqual(str, "") ) break ;
      printf("The acronym is %s.\n", Acronym(str)) ;
   }
}


/* The acronym function */
string Acronym(string str) {
   int i, n ;
   char first ;
   string acronym ;

   acronym = CharToString(IthChar(str,0)) ;
   n = StringLength(str) ;
   for (i = 1 ; i < n ; i++) {
      if ( IthChar(str,i) == ' ') {
	 first = IthChar(str,i+1) ;
	 acronym = Concat(acronym,CharToString(first)) ;
      }
   } 
   return(acronym) ;
}

