/***********************************************************************
 * strlen.c --- Compute and display the length of strings, pointer
 *              version.
 *
 * Tom Kelliher
 *
 * Input: Strings.
 *
 * Output: The length of each string input.
 *
 * Notes: Enter a null string to exit.  Only the first 255 characters
 * of the input string will be read.
 ***********************************************************************/

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

int main()
{
   char str[256];   /* Load the base address of your buffer into $s0.
                     * Use the following assembler directive in your 
                     * data segment to create this buffer:
                     *
                     *    str: .space 256
                     */

   char *ptr;       /* Use $s1 to store ptr. */

   printf("Enter a string: ");
   fgets(str, 256, stdin);   /* Use the read_string system call (8). */
   ptr = str;

   while (*ptr != '\n')
   {
      while (*ptr != '\0')
         ptr++;

      /* Subtract one because I don't want to include the newline
       * character at the end of the string in the length of the string.
       */

      printf("Length of string: %d.\n", ptr - str - 1);

      printf("Enter a string: ");
      fgets(str, 256, stdin);
      ptr = str;
   }

   exit(0);
}
