fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. #define BASE 65
  5. /*
  6.  * A = 65 (Dec) => 0
  7.  * z = 122 (Dec) => 57
  8.  */
  9.  
  10. static void
  11. process_string (char *str)
  12. {
  13. char *ptr = str;
  14. uint64_t map = 0; /* 64 bit integer */
  15. int ascii = 0, ix = 0;
  16.  
  17. while (*ptr != '\0') {
  18. ascii = (int) *ptr;
  19. ix = ascii - BASE;
  20. if ((map & (1ULL<<ix)) == 0) {
  21. *str++ = *ptr;
  22. map = map | (1ULL<<ix);
  23. }
  24. ptr++;
  25. }
  26. *str = '\0';
  27. return;
  28. }
  29.  
  30. int main (void)
  31. {
  32. char str[BUFSIZ] = "Geeksforgeeks";
  33. printf("string: %s\n", str);
  34. process_string(str);
  35. printf("\nFinal string: %s\n", str);
  36. return 0;
  37. }
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
string: Geeksforgeeks

Final string: Geksforg