fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <cctype>
  4.  
  5. int main() {
  6. char str[100] = "str,, ing";
  7. int bad = 0;
  8. int cur = 0;
  9. while (str[cur] != '\0') {
  10. if (bad < cur && !ispunct(str[cur]) && !isspace(str[cur])) {
  11. str[bad] = str[cur];
  12. }
  13. if (ispunct(str[cur]) || isspace(str[cur])) {
  14. cur++;
  15. }
  16. else {
  17. cur++;
  18. bad++;
  19. }
  20. }
  21. str[bad] = '\0';
  22. fprintf(stdout, "cur = %d; bad = %d; str = %s\n", cur, bad, str);
  23. return 0;
  24. }
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
cur = 9; bad = 6; str = string