home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_12 / 9n12124a < prev    next >
Text File  |  1991-09-24  |  2KB  |  89 lines

  1.  
  2. Listing 7
  3. **********
  4.  
  5. #include <ctype.h>
  6. #include <stdio.h>
  7.  
  8. #define TRUE 1
  9. #define FALSE 0
  10.  
  11. int get_line(char *text_in, int size_text_in);
  12. int put_line(char *text_out, int size_text_out);
  13.  
  14. void main()
  15.     {
  16.  
  17. #define SIZE_TEXT 1024
  18.     char text[SIZE_TEXT];
  19.     int size;
  20.     int spaces;
  21.     size = get_line(text, SIZE_TEXT);
  22.     spaces = put_line(text, size);
  23.     printf ("Sentence is %d \n", size);
  24.     printf ("And has %d spaces in it\n", spaces);
  25.     }
  26.  
  27. int get_line(text_in, size_text_in)
  28. /* Gets a line of text and returns number of characters
  29.     (not counting newline) */
  30. char *text_in ;   /* Where to put the input text */
  31. int size_text_in; /* Size of text_in */
  32.     {
  33.     int ret;
  34.     char *cret;
  35.  
  36.     printf ("Enter Text : ");
  37.  
  38.     cret = fgets(text_in, size_text_in, stdout);
  39.     if (cret !=NULL)
  40.         ret = strlen(text_in) - 1;
  41.     else
  42.         ret = - 1;
  43.  
  44.     return ret;
  45.     }
  46.  
  47. put_line(text_out, size_text_out)
  48. /* This outputs a line of text with the first letter of each word
  49.     upper-cased */
  50. char *text_out;     /* Text to output */
  51. int size_text_out;  /* Size of text */
  52.     {
  53.     int i;
  54.     int print_as_uppercase;
  55.     char chr;
  56.     int spaces;
  57.  
  58.     print_as_uppercase = TRUE;
  59.     spaces = 0;
  60.  
  61.     printf ("Text is    : ");
  62.  
  63.     for (i = 0; i < size_text_out; i++)
  64.         {
  65.         chr = text_out[i];
  66.         if (print_as_uppercase)
  67.            {
  68.            printf("%c",toupper(chr));
  69.            print_as_uppercase = FALSE;
  70.            }
  71.         else
  72.            {
  73.            printf("%c",tolower(chr));
  74.            }
  75.         if (isspace(chr))
  76.            {
  77.            print_as_uppercase = TRUE;
  78.            spaces++;
  79.            }
  80.         if (chr == '.' || chr == ',')
  81.             print_as_uppercase = TRUE;
  82.         }
  83.     printf("\n");
  84.     return spaces;
  85.     }
  86.  
  87. ********
  88.  
  89.