Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<ctype.h>
- int main(void) {
- int max_user;
- char cardinal[10][10] = {"1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th"};
- char username[10][50];
- char* temp;
- char password[10][50];
- char newpassword[10][50];
- char email[10][50];
- char *p;
- do { //Maximum users
- printf("Input max user (3-10) : "); scanf("%d", &max_user); fflush(stdin);
- }while (max_user > 10 || max_user < 3);
- bool unique;
- for (int i = 0; i < max_user; i++) {
- do {
- unique = true; //Check if the username inputted has been inputted before
- printf("Input the %s username : ", cardinal[i]); scanf("%s", &username[i]); fflush(stdin);
- if(i!=0) {
- for (int a = 0; a < i; a++) {
- if(strcmp(username[i], username[a]) == 0) {
- unique = false;
- break;
- }
- }
- }
- }while(unique == false);
- do { //Password needs to be at least 5 characters
- printf("Input Password (Min 5 characters) : ");
- scanf("%s", &password[i]); fflush(stdin);
- }while(strlen(password[i]) < 5);
- printf("\nPassword converted ...\n");
- int n = strlen(password[i]);
- for (int a = 0; a < n; a++) {
- if (a == 0) { //First and last character are changed into upper case
- password[i][a] = toupper(password[i][a]);
- }else if(a == n-1) {
- password[i][a] = toupper(password[i][a]);
- }else { //Other characters are changed into lower case
- password[i][a] = tolower(password[i][a]);
- }
- switch(password[i][a]) { //Changing password
- case 'O' :
- password[i][a] = '0'; break;
- case 'o' :
- password[i][a] = '0'; break;
- case 'I' :
- password[i][a] = '1'; break;
- case 'i' :
- password[i][a] = '1'; break;
- case 'S' :
- password[i][a] = '$'; break;
- case 's' :
- password[i][a] = '$'; break;
- case 'T' :
- password[i][a] = '7'; break;
- case 't' :
- password[i][a] = '7';
- }
- }
- strcat(password[i], "!"); //Adding a "!" to password array
- //By now, password array has fundamentally changed, so program will ask user to
- // input new password, which will be compared to password array
- printf("New password is %s\n\n", password[i]);
- do {
- printf("Now please enter your new password : ");
- scanf("%s", newpassword[i]); fflush(stdin);
- }while(strcmpi(newpassword[i], password[i]) != 0);
- bool pass;
- do {
- pass = false; //Initializing boolean value of pass
- printf("Nice! Please enter your email : ");
- scanf("%s", email[i]); fflush(stdin);
- int x = strlen(email[i]);
- char* p = &email[i][(x - 10)];
- //The output of strstr is a pointer, so we initialize value of p as
- // "the adress" of email[i][x - 10]. 10 Because @gmail.com as well as
- // @yahoo.com contains 10 character
- if (p == strstr(email[i], "@gmail.com") || p == strstr(email[i], "@yahoo.com")) {
- //Here you can see we compare p to strstr, and if inputted email successfully
- //goes through this selection, then boolean value of pass becomes true
- //These all will be done again and again if inputted email fails to go through
- //this selection
- pass = true;
- }
- }while (pass == false);
- system("cls");
- }
- printf("%-10s %-20s\n\n", "Name", "Email");
- for(int i = 0 ; i < max_user; i++) {
- printf("%-10s %-20s\n", username[i], email[i]);
- }
- printf("Thank you for using this program ");
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement