Design for my_gets()


Design needs


Design Outline


Code/Pseudocode Design

The following design does NOT give the user the option of inputting another string if the one they input is too long and gets truncated. Your version should do this.

      void my_gets(char array, int max_chars)
      {
         int iochar, i = 0;

         do
         {
            iochar = getchar();
            if (iochar != '\n')
            {
               array[i] = iochar;
               i++;
            }
         }
         while ((iochar != '\n') && (i < max_chars - 1));
         array[i] = '\0';
         if (iochar != '\n')
             get another character
             if it is not a carriage return then give an error message and
                 clean the input stream.
      }