Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Language: C99 a) Write a function, void remove_white_spaces(char *s) which mutat

ID: 3729475 • Letter: L

Question

Language: C99

a) Write a function, void remove_white_spaces(char *s) which mutates the string s so that all white spaces characters are removed from the string.

b) Write a function, void remove_char(char *s, char c) which mutates the string s so that all instances of the character c are removed from the string.

c) Write a function, void remove_chars(char *s, const char disallowed_chars[], int len) which mutates the string s so that all instances of the characters inside the array disallowed_chars are removed from the string.

d) Write a function bool is_valid_password(const char *s) which determines whether or not the string s is a valid password according to the usual convoluted rules below. Your password must contain...

at least 8 characters

at least one upper case letter (e.g., 'T')

at least one lower case letter (e.g., 'r')

at least one digit (e.g., '1')

at least one special character (e.g., '$') -- see below

Special characters are non-whitespace printable characters that are not mentioned above.

Explanation / Answer

#include <stdio.h>
#include <stdbool.h>
void remove_white_spaces(char *s)// (a)
{
   int p1 = 0, p2 = 0;
   while(s[p2]!=''){
       if(s[p2]!=' '){
           s[p1] = s[p2];
           p1++;
       }
       p2++;
   }
   s[p1]='';
}

void remove_char(char *s, char c)// (b)
{
   int p1 = 0, p2 = 0;
   while(s[p2]!=''){
       if(s[p2]!= c){
           s[p1] = s[p2];
           p1++;
       }
       p2++;
   }
   s[p1]='';
}
void remove_chars(char *s, const char disallowed_chars[], int len) //(c) assuming len as length of disallowed_char[]
{
       for(int i = 0;i<len; i++)
       {
           char c = disallowed_chars[i];
           int p1 = 0, p2 = 0;
               while(s[p2]!=''){
               if(s[p2]!= c){
                   s[p1] = s[p2];
                   p1++;
               }
               p2++;
           }
           s[p1]='';
       }
}

bool is_valid_password(const char *s) //(d)
{
   bool dig = false,uppercase = false, lowercase = false, special = false;
   int len = 0;
   while(s[len]!='')
   {
       if(s[len]<='9' && s[len]>='0')
               dig = true;
       else if(s[len]<='Z' && s[len]>='A')
           uppercase = true;
       else if(s[len]<='z' && s[len]>='a')
           lowercase = true;
       else if(s[len]!=' ')
           special = true;
       len++;
   }
   if(len>=8 && dig && lowercase && uppercase && special)
       return true;
   else
       return false;
}
int main()
{
  
   char s[] = "Hi This is ankit here    bye";
   remove_white_spaces(s);
   printf("The string after removing spaces : %s ",s);
   char s1[] = "The quick brown fox jumped just";
   char c = 'o';
   remove_char(s1,c);
   printf("the String after removing character %c : %s ",c,s1);
   char s2[] = "The quick brown fox jumped just aejju";
   const char ch[5] = {'a','e', 'i','o','u'};
   remove_chars(s2,ch,5);
   printf("string after removing vowels: %s ",s2);
   const char s3[] = "MC@kejriwal12";
   printf("%d",is_valid_password(s3));
   return 0;
}