fork(1) download
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4.  
  5. void truncW (char t[], int n) {
  6. int s = strlen(t);
  7. for (int i = 0, j = 0; i < s; i++, j++) {
  8. if (isspace(t[i]) > 0) {
  9. // printf("%d, %d, %d, '%c'", i, j, s, t[i]);
  10. j = -1;
  11. printf(" ");
  12. } else if (j < n) {
  13. printf("%c", t[i]);
  14. }
  15. }
  16. }
  17.  
  18. int main(void) {
  19. char t[] = "liberdade, igualdade e fraternidade";
  20. truncW(t, 4);
  21. }
  22.  
  23. //https://pt.stackoverflow.com/q/54433/101
Success #stdin #stdout 0s 4272KB
stdin
Standard input is empty
stdout
libe igua e frat