#include <stdio.h>
#include <stdint.h>
void remove_duplicates(char *str) {
uint8_t i = 0, j = 0;
char seen[256] = {0}; // ASCII character map
while (str[i]) {
if (!seen[(uint8_t)str[i]]) {
seen[(uint8_t)str[i]] = 1;
str[j++] = str[i];
}
i++;
}
str[j] = '\0'; // Null-terminate the result
}
int main() {
char str[101];
fgets(str, sizeof(str), stdin);
// Remove newline
uint8_t i = 0;
while (str[i]) {
if (str[i] == '\n') {
str[i] = '\0';
break;
}
i++;
}
remove_duplicates(str);
printf("%s", str);
return 0;
}1. Track seen characters
seen[256] to represent all possible ASCII characters.seen['e'], seen['m'], etc.).0.2. Iterate through the input string
i: scans the original stringj: builds the result in-place3. Check if character is already seen
seen[str[i]] == 0, it’s the first time we’ve seen this character:seen[str[i]] = 1str[i] to str[j]jseen[str[i]] == 1, skip it.4. Terminate the result
str[j] = '\0' to properly end the string.
🧩 Embedded-Friendly Notes
char, uint8_t, and fixed-size arrays
Input
programming
Expected Output
progamin