fork download
  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. int main() {
  6. char str[100];
  7. char *p, *q;
  8.  
  9. printf("Enter a string: ");
  10. fgets(str, sizeof(str), stdin);
  11.  
  12. // Remove newline
  13. str[strcspn(str, "\n")] = '\0';
  14.  
  15. p = str;
  16.  
  17. while (*p != '\0') {
  18. int count = 0;
  19. q = str;
  20.  
  21. // Count occurrences of *p
  22. while (*q != '\0') {
  23. if (*p == *q)
  24. count++;
  25. q++;
  26. }
  27.  
  28. // If repeated, remove using memmove
  29. if (count > 1) {
  30. memmove(p, p + 1, strlen(p));
  31. } else {
  32. p++; // Move to next character only if not deleted
  33. }
  34. }
  35.  
  36. printf("Non-repeated characters: %s\n", str);
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 5264KB
stdin
Banana
stdout
Enter a string: Non-repeated characters: Bna