Untitled
unknown
plain_text
2 years ago
1.1 kB
2
Indexable
#define _CRT_SECURE_NO_WARNINGS #include <string.h> #include <stdio.h> #include <stdlib.h> void Error(char* msg){fprintf(stderr, "Error:%s\n", msg); exit(1);} int main(int argc, char* argv[]) { int counter = 0; //variable that counts the appearances of the letters in the given name. int i; int j; char* name = argv[1]; //defining name variable char* letters = argv[2];//defining letters variable if(strlen(name) == 0 || strlen(letters) == 0) Error("either the name or the letters are empty\n"); if(argc != 3) Error("Bad number of parameters\n"); for(i=0;i<strlen(name);i++) // pass through all the letters in the given name. { for(j=0;j<strlen(letters);j+=2) /* pass through all the letters and check if specific letter of the name shown in the string of the letters.*/ { if(name[i] == letters[j]) /*if the letter found, updating the counter and get out of the second loop.*/ { counter++; break; } } } if(counter==(strlen(name))) printf("\n%s exist\n\n", name); else printf("\n%s not exist\n\n", name); return 0; }
Editor is loading...