1
0

test_fit.c 526 B

123456789101112131415161718192021222324
  1. /* test_fit.c -- try the string-shrinking function */
  2. #include <stdio.h>
  3. #include <string.h> /* contains string function prototypes */
  4. void fit(char *, unsigned int);
  5. int main(void)
  6. {
  7. char mesg[] = "Things should be as simple as possible,"
  8. " but not simpler.";
  9. puts(mesg);
  10. fit(mesg,38);
  11. puts(mesg);
  12. puts("Let's look at some more of the string.");
  13. puts(mesg + 39);
  14. return 0;
  15. }
  16. void fit(char *string, unsigned int size)
  17. {
  18. if (strlen(string) > size)
  19. string[size] = '\0';
  20. }