1.Ask user to enter three words. You can assume that each word has the maximum
length of five characters.
2. Combine the three words to form a passphrase. For example, if the user enters the
words “I”, “love” and “you”, the passphrase should be “Iloveyou”.
3. Ask user to enter a passphrase. Check whether the passphrase entered by the user is
the same as the passphrase generated in Step 2 above. If the passphrase entered is
the same, prints out “Passphrase is correct!”. Otherwise, prints out “Wrong
passphrase!”.
#include <stdio.h>
#include <string.h>
int main()
{
char word1[5];
char word2[5];
char word3[5];
char passphrase[15];
//get the first word from the user
printf("Enter the first word: ");
scanf("%s",word1);
//get the second word from the user
printf("Enter the second word: ");
scanf("%s",word2);
//get the third word from the user
printf("Enter the third word: ");
scanf("%s",word3);
//Combine the three words to form a passphrase.
strcat(word1,word2);
strcat(word1,word3);
// Ask user to enter a passphrase.
printf("Enter a passphrase: ");
scanf("%s",passphrase);
// Check whether the passphrase entered by the user is
//the same as the passphrase generated
if(strcmp(word1,passphrase)==0){
//If the passphrase entered is the same, prints out "Passphrase is correct!".
printf("Passphrase is correct!\n\n");
}else{
//Otherwise, prints out "Wrong passphrase!"
printf("Wrong passphrase!\n\n");
}
getchar();
getchar();
return 0;
}
Comments
Leave a comment