Last active
November 8, 2022 06:41
-
-
Save pwnwriter/9b614f9023ba1fd82ff5371575404094 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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