Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. short isNotEqual(char tmpChar, char* usedChars) {
  4. for (int i = 0; i < strlen(usedChars); i++)
  5. if (usedChars[i] == tmpChar)
  6. return 0;
  7. return 1;
  8. }
  9.  
  10. void findEqualElem(char* str, char* newStr) {
  11. char tmpChar;
  12. int counter = 0;
  13. int index = 0;
  14. char usedChars[50];
  15. for (int i = 0; i < strlen(str); i++) {
  16. tmpChar = str[i];
  17. for (int j = i + 1; j < strlen(str); j++)
  18. if (tmpChar == str[j] && (isNotEqual(tmpChar, usedChars) == 1)) {
  19. counter++;
  20. newStr[index] = tmpChar;
  21. index++;
  22. }
  23. if (counter > 0) {
  24. newStr[index] = tmpChar;
  25. index++;
  26. }
  27. counter = 0;
  28. usedChars[i] = tmpChar;
  29. }
  30. }
  31.  
  32. int main() {
  33. printf("Enter the string: ");
  34. char str[80];
  35. gets(str);
  36. char newStr[80];
  37. findEqualElem(str, newStr);
  38. printf("Result - ");
  39. int i = 0;
  40. while (newStr[i] > 0) {
  41. printf("%c", newStr[i]);
  42. i++;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement