1
0

mod_str.c 883 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /* mod_str.c -- modifies a string */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #define LIMIT 81
  6. void ToUpper(char *);
  7. int PunctCount(const char *);
  8. int main(void)
  9. {
  10. char line[LIMIT];
  11. char * find;
  12. puts("Please enter a line:");
  13. fgets(line, LIMIT, stdin);
  14. find = strchr(line, '\n'); // look for newline
  15. if (find) // if the address is not NULL,
  16. *find = '\0'; // place a null character there
  17. ToUpper(line);
  18. puts(line);
  19. printf("That line has %d punctuation characters.\n",
  20. PunctCount(line));
  21. return 0;
  22. }
  23. void ToUpper(char * str)
  24. {
  25. while (*str)
  26. {
  27. *str = toupper(*str);
  28. str++;
  29. }
  30. }
  31. int PunctCount(const char * str)
  32. {
  33. int ct = 0;
  34. while (*str)
  35. {
  36. if (ispunct(*str))
  37. ct++;
  38. str++;
  39. }
  40. return ct;
  41. }