Ethan O.

asked • 01/29/20

Can some help me fix my code

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

//include <conio.h>


#define MAX_NAME_LENGTH (20)

#define PW_INVALID_SIZE (1)

#define PW_MISSING_UPPERCASE_LETTER (2)

#define PW_MISSING_LOWERCASE_LETTER (4)

#define PW_MISSING_DIGIT (8)

#define PW_MISSING_PUNCTUATION (16)

#define PUNCTUATION_CHARS ("?,.;!:")


char* PromptForInput(char promptMsg[], char responseBuff[])


{


if (promptMsg!=NULL)

{

printf(promptMsg);

}

printf(": ");

scanf("%s",responseBuff);

return(responseBuff);

}


int Names(char name[])

{

char first[MAX_NAME_LENGTH];

char mid[MAX_NAME_LENGTH];

char last[MAX_NAME_LENGTH];

int count = 0;

int holder = 0;

name = PromptForInput("Please input your name",name);

for(int i = 0; i < strlen(name); i++){

if(name[i] != ' '){

first[count] = name[i];

count++;

} else {

holder = i;

count = 0;

}

}

for(int i = holder; i < strlen(name); i--){

if(name[i] != ' '){

mid[count] = name[i];

count++;

} else {

holder = i;

count = 0;

}

}

for(int i = holder; i < strlen(name); i++){

if(name[i] != ' '){

last[count] = name[i];

count++;

}


}

printf("Name is: %s", last);

printf(", %s", first);

printf(" %s", mid);

return( strlen(name));

}


int Password( char * pwBuff)


{

PromptForInput("\nPlease input the password",pwBuff);

int iReturn = 0;

int uCaseFlag = 0;

int lCaseFlag = 0;

int digitFlag=0;

int punctFlag=0;

int iLoop;

char ch;

int pwLength = strlen(pwBuff);


for (iLoop=0; iLoop<pwLength; iLoop++)

{

ch = pwBuff[iLoop];

if ((ch>=65) && (ch<=90)) { uCaseFlag=1; }

if ((ch>=97) && (ch<=122)) { lCaseFlag=1; }

if ((ch>=48) && (ch<=57)) { digitFlag=1; }

punctFlag = (strchr(PUNCTUATION_CHARS,ch)!=NULL) ? 1 : 0;

}

if ((pwLength <6) || (pwLength>14))

{

iReturn -= PW_INVALID_SIZE;

}

if (uCaseFlag==0) { iReturn -= PW_MISSING_UPPERCASE_LETTER; }

if (lCaseFlag==0) { iReturn -= PW_MISSING_LOWERCASE_LETTER; }

if (digitFlag==0) { iReturn -= PW_MISSING_DIGIT; }

if (punctFlag==0) { iReturn -= PW_MISSING_PUNCTUATION; }

return(iReturn);


} /* Password */




int main()

{

char name[MAX_NAME_LENGTH];

char pwBuff[255];


Names(name);



int iReturn = Password(pwBuff);


printf("Password is %s \n",pwBuff);


if (iReturn==0)


{

printf("Password is CORRECT !!! \n");

}


else

{

int X = abs(iReturn);

printf("The Password is Incorrect \n");

if (X / PW_MISSING_PUNCTUATION)


{


printf("Password must contain one of the following punctuation symbols: %s \n",PUNCTUATION_CHARS);


X %= PW_MISSING_PUNCTUATION;


}


if (X / PW_MISSING_DIGIT)


{

printf("Password must contain at least one digit \n");

X %= PW_MISSING_DIGIT;

}


if (X / PW_MISSING_LOWERCASE_LETTER)


{

printf("Password must contain at least one lowercase letter \n");

X %= PW_MISSING_LOWERCASE_LETTER;

}


if (X / PW_MISSING_UPPERCASE_LETTER)

{

printf("Password must contain at least one uppercase letter \n");

X%= PW_MISSING_UPPERCASE_LETTER;

}


if (X/PW_INVALID_SIZE)

{

printf("Password must be between 6 and 14 characters \n");

}

} /* password validation */


return 0;



}


1 Expert Answer

By:

Patrick B. answered • 02/02/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.