Skip to content

Instantly share code, notes, and snippets.

@pwnwriter
Last active November 8, 2022 06:41
Show Gist options
  • Save pwnwriter/9b614f9023ba1fd82ff5371575404094 to your computer and use it in GitHub Desktop.
Save pwnwriter/9b614f9023ba1fd82ff5371575404094 to your computer and use it in GitHub Desktop.
/*This gist consists of the solution of ITSNP posted on April 28
Link of the post " https://www.facebook.com/101470728764629/posts/336507348594298/ "
Here's the solution in c ! */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int
main(int argc, char **argv)
{
char *input, *unique_chars_list;
int input_len, list_c;
/* = PREREQUISITES = */
/* argument checking */
if (argc < 2) {
fprintf(stderr, "usage: %s string\n", argv[0]);
exit(EXIT_FAILURE);
}
input = argv[1];
input_len = strlen(input);
/* allocate memory for the list */
unique_chars_list = malloc(sizeof(char) * input_len);
list_c = 0;
/* = ACTUAL WORK = */
unique_chars_list[list_c++] = tolower(input[0]);
for (int i = 1; i < input_len; i++) {
if (tolower(input[i-1]) != tolower(input[i]))
unique_chars_list[list_c++] = tolower(input[i]);
}
unique_chars_list[++list_c] = '\0';
/* Print output */
printf("Input: '%s', Output: '%s'\n", input, unique_chars_list);
/* cleanup */
free(unique_chars_list);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment