/* File: acro2.c
   Implements and tests the Acronym function.
*/

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

/* Function Prototype */
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) {
   char c ;
   int i, n ;
   string acronym ;
   bool first_letter;

   acronym = "" ;
   first_letter = TRUE ;
   n = StringLength(str) ;
   for (i = 0 ; i < n ; i++) {
      c = IthChar(str, i) ;
      if ( first_letter && !isspace(c) ) {
         acronym = Concat(acronym, CharToString(c)) ;
         first_letter = FALSE ;
      } else if ( !first_letter && isspace(c) ) {
	 first_letter = TRUE ; 
      }
   } /* end for loop */
   return(acronym) ;
}

