Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdbool.h>
- #include <string.h>
- bool isUpper(int);
- bool isLower(int);
- bool isSubstring(char*, char*);
- int toUpper(int);
- void removeNewLines(char*);
- int main(int argc, char *argv[]){
- (void)argc;
- char city[100];
- char cities[42][100];
- char possibleChars[100];
- int possibleCharsIndex = 0;
- int i = 0;
- int state = 0;
- for (unsigned int i = 0; i < strlen(argv[1]); i++) {
- argv[1][i] = toUpper(argv[1][i]);
- }
- while (fgets(city, 100, stdin) != NULL) {
- for (unsigned int i = 0; i < strlen(city); i++) {
- city[i] = toUpper(city[i]);
- }
- removeNewLines(city);
- strcpy(cities[i++], city);
- }
- for (unsigned int i = 0; i < 42; i++) {
- if(strcmp(argv[1], cities[i]) == 0){
- printf("FOUND: %s\n", cities[i]);
- state = 1;
- }
- }
- if (state == 0) {
- for (unsigned int i = 0; i < 42; i++) {
- if(isSubstring(argv[1], cities[i])){
- possibleChars[possibleCharsIndex] = cities[i][strlen(argv[1])];
- possibleCharsIndex++;
- state = 2;
- }
- }
- }
- if (state == 2) {
- printf("ENABLE: ");
- for (unsigned int i = 0; i < 50; i++) {
- printf("%d: %c\n", i, possibleChars[i]);
- }
- printf("\n");
- } else if(state == 0){
- printf("NOT FOUND\n");
- }
- return 0;
- }
- bool isUpper(int c){
- return c >= 'A' && c <= 'Z';
- }
- bool isLower(int c){
- return c >= 'a' && c <= 'z';
- }
- int toUpper(int c){
- if(isUpper(c)){
- return c;
- } else if(isLower(c)){
- return c - 'a' + 'A';
- } else {
- return c;
- }
- }
- bool isSubstring(char *sub, char *base){
- if (strlen(sub) > strlen(base)) {
- return false;
- } else {
- bool isSubstring = true;
- for (unsigned int i = 0; i < strlen(sub); i++) {
- if(sub[i] != base[i]) isSubstring = false;
- }
- return isSubstring;
- }
- }
- void removeNewLines(char *word){
- for (unsigned int i = 0; i < strlen(word); i++) {
- if(word[i] == 10){
- word[i] = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement