├── .gitignore ├── Images ├── PMS_05_User_Panel.png ├── PMS_15_ExitScreen.png ├── PMS_02_Login_Screen.png ├── PMS_04_Admin_Panel.png ├── PMS_09_SeachByName.png ├── PMS_00_UseCaseDiagram.png ├── PMS_06_AddNewContact.png ├── PMS_07_UpdateContact.png ├── PMS_10_SearchByNumber.png ├── PMS_12_DeleteContact.png ├── PMS_14_NoContactError.png ├── PMS_11_SearchByCityName.png ├── PMS_13_DeleteAllContacts.png ├── PMS_01_Introduction_Screen.png ├── PMS_03_Admin_Login_Secure.png └── PMS_08_DisplayAllContacts.png ├── Documents ├── PhonebookManagementSystem_Synopsis.pdf └── PhonebookManagementSystem_UseCaseDiagram.pdf ├── Code Files ├── ContactList.txt └── main.c ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.exe 2 | .vscode/ 3 | Code\ Files/temporary.txt -------------------------------------------------------------------------------- /Images/PMS_05_User_Panel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_05_User_Panel.png -------------------------------------------------------------------------------- /Images/PMS_15_ExitScreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_15_ExitScreen.png -------------------------------------------------------------------------------- /Images/PMS_02_Login_Screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_02_Login_Screen.png -------------------------------------------------------------------------------- /Images/PMS_04_Admin_Panel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_04_Admin_Panel.png -------------------------------------------------------------------------------- /Images/PMS_09_SeachByName.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_09_SeachByName.png -------------------------------------------------------------------------------- /Images/PMS_00_UseCaseDiagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_00_UseCaseDiagram.png -------------------------------------------------------------------------------- /Images/PMS_06_AddNewContact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_06_AddNewContact.png -------------------------------------------------------------------------------- /Images/PMS_07_UpdateContact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_07_UpdateContact.png -------------------------------------------------------------------------------- /Images/PMS_10_SearchByNumber.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_10_SearchByNumber.png -------------------------------------------------------------------------------- /Images/PMS_12_DeleteContact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_12_DeleteContact.png -------------------------------------------------------------------------------- /Images/PMS_14_NoContactError.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_14_NoContactError.png -------------------------------------------------------------------------------- /Images/PMS_11_SearchByCityName.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_11_SearchByCityName.png -------------------------------------------------------------------------------- /Images/PMS_13_DeleteAllContacts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_13_DeleteAllContacts.png -------------------------------------------------------------------------------- /Images/PMS_01_Introduction_Screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_01_Introduction_Screen.png -------------------------------------------------------------------------------- /Images/PMS_03_Admin_Login_Secure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_03_Admin_Login_Secure.png -------------------------------------------------------------------------------- /Images/PMS_08_DisplayAllContacts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Images/PMS_08_DisplayAllContacts.png -------------------------------------------------------------------------------- /Documents/PhonebookManagementSystem_Synopsis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Documents/PhonebookManagementSystem_Synopsis.pdf -------------------------------------------------------------------------------- /Documents/PhonebookManagementSystem_UseCaseDiagram.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alkaison/Phonebook-Management-System/HEAD/Documents/PhonebookManagementSystem_UseCaseDiagram.pdf -------------------------------------------------------------------------------- /Code Files/ContactList.txt: -------------------------------------------------------------------------------- 1 | suresh kumar m 8422882287 thane 2 | abrar shaikh m 8545525632 malegaon 3 | roshni verma f 8422882286 majiwade 4 | aditya tiwari m 7594854565 thane 5 | rajesh sharma m 8924073774 panvel 6 | ganesh mourya m 9137141840 thane 7 | karan kumar m 8422882284 thane 8 | gaurav manohar m 9021409095 kalyan 9 | mukesh patel m 8452458565 kurla 10 | asha vishwakarma f 7595455412 thane 11 | sahyog college m 8422882285 thane 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Alkaison 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Phonebook Management System 3 | 4 | Phonebook Management System in the C programming language is a software application that allows users to store, organize and manage large numbers of contact records efficiently. The system is designed to have functions such as adding, updating, viewing, listing and deleting contacts. 5 | 6 | ## Description 7 | 8 | You can learn the fundamentals of functions, file handling, and data 9 | structure by working on the Phonebook Management System. 10 | This system will show you how to add, list, change or edit, search for, and 11 | remove data from/to a file. The functions that make up this project's menu 12 | include adding new records, listing them, editing and updating them, looking 13 | for saved contacts, and deleting phonebook entries. 14 | 15 | ## Documents 16 | 17 | - Synopsis report [here](/Documents/PhonebookManagementSystem_Synopsis.pdf "Synopsis Report") 18 | - Use case diagram [here](/Documents/PhonebookManagementSystem_UseCaseDiagram.pdf "Use Case Diagram") 19 | - Output Images [here](/Images/) 20 | 21 | **Note:** If the documents are not rendering on github please download the repository [here](https://github.com/Alkaison/Phonebook-Management-System/archive/refs/heads/main.zip "Latest Code"). 22 | 23 | ## Features 24 | 25 | We have used many functions in this project. These functions are very easy to understand as their name itself signifies their respective operations. 26 | 27 | - Login Page 28 | - Secure Password Login 29 | - Admin Panel 30 | - User Panel 31 | - Unique phone numbers 32 | - Advance validation function for user input 33 | - Add New Contact 34 | - Update Contact 35 | - Display All Contact 36 | - Search By Name 37 | - Search By Number 38 | - Search By City 39 | - Delete Contact 40 | - Delete All Contact 41 | 42 | ### **Password: Admin** 43 | 44 | ## Requirements for using it 45 | 46 | - A software (IDE) for reviewing the code 47 | - C/C++ compiler (Recommended: GCC Compiler) 48 | - Command Prompt or Windows Powershell 49 | 50 | **Note:** This program won't run on online compilers as they don't provide libraries for FILE Management & external storing. 51 | 52 | ## Contributing 53 | 54 | - If you wish to contribute a new function or want to improve the code quality, you are welcome for your contributions. 55 | 56 | - Fork the repository & make changes, after completion open pull request. 57 | 58 | - Thanks in advance 💛 59 | 60 | ## Screenshots 🖼️ 61 | 62 | ### 01. Introduction Screen 63 | 64 | ![Information Page](https://i.ibb.co/rktHD2C/PMS-01-Introduction-Screen.png) 65 | 66 | ### 02. Login Screen 67 | 68 | ![Login Page](https://i.ibb.co/vYn8Fnm/PMS-02-Login-Screen.png) 69 | 70 | ### 03. Secure Password Login 71 | 72 | ![Secure Password Login](https://i.ibb.co/KzPmpFF/PMS-03-Admin-Login-Secure.png) 73 | 74 | ### 04. Admin Panel 75 | 76 | ![Admin Panel](https://i.ibb.co/Fb0gfXv/PMS-04-Admin-Panel.png) 77 | 78 | ### 05. User Panel 79 | 80 | ![User Panel](https://i.ibb.co/743mZbx/PMS-05-User-Panel.png) 81 | 82 | ### 06. Add New Contact 83 | 84 | ![Add New Contact](https://i.ibb.co/YtvXhJs/PMS-06-Add-New-Contact.png) 85 | 86 | ### 07. Update Contact 87 | 88 | ![Update Contact](https://i.ibb.co/vvvXRhh/PMS-07-Update-Contact.png) 89 | 90 | ### 08. Display All Contact 91 | 92 | ![Display All Contact](https://i.ibb.co/p2x9cvx/PMS-08-Display-All-Contacts.png) 93 | 94 | ### 09. Search By Name 95 | 96 | ![Search By Name](https://i.ibb.co/3MGKWmn/PMS-09-Seach-By-Name.png) 97 | 98 | ### 10. Search By Number 99 | 100 | ![Search By Number](https://i.ibb.co/0tL532S/PMS-10-Search-By-Number.png) 101 | 102 | ### 11. Search By City Name 103 | 104 | ![Search By City Name](https://i.ibb.co/hyXZMhd/PMS-11-Search-By-City-Name.png) 105 | 106 | ### 12. Delete Contact 107 | 108 | ![Delete Contact](https://i.ibb.co/6DYFThb/PMS-12-Delete-Contact.png) 109 | 110 | ### 13. Delete All Contact 111 | 112 | ![Delete All Contact](https://i.ibb.co/BP5CdYT/PMS-13-Delete-All-Contacts.png) 113 | 114 | ### 14. No Contacts Error 115 | 116 | ![No Contacts Error](https://i.ibb.co/LSzLfZ8/PMS-14-No-Contact-Error.png) 117 | 118 | ### 15. Exit Screen 119 | 120 | ![Exit Screen](https://i.ibb.co/N3z5qqM/PMS-15-Exit-Screen.png) 121 | 122 | ## MIT LICENSE 📔 123 | 124 | ```LICENSE 125 | MIT License 126 | 127 | Copyright (c) 2022 Alkaison 128 | 129 | Permission is hereby granted, free of charge, to any person obtaining a copy 130 | of this software and associated documentation files (the "Software"), to deal 131 | in the Software without restriction, including without limitation the rights 132 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 133 | copies of the Software, and to permit persons to whom the Software is 134 | furnished to do so, subject to the following conditions: 135 | 136 | The above copyright notice and this permission notice shall be included in all 137 | copies or substantial portions of the Software. 138 | 139 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 140 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 141 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 142 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 143 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 144 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 145 | SOFTWARE. 146 | ``` 147 | -------------------------------------------------------------------------------- /Code Files/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Project Title: Phonebook Management System 3 | Language: C 4 | GitHub Repository: https://github.com/Alkaison/Phonebook-Management-System 5 | BSc IT Course => Project for Semester-1 6 | Concepts: File Handling, Struct, Define, etc. 7 | */ 8 | #include // almost everything 9 | #include // system() 10 | #include // strcmp(), strlen() 11 | #include // getch() 12 | #include // Sleep() => for windows OS 13 | #include // for linux or Mac OS 14 | #include // isdigit(), isaplha() 15 | 16 | // define constants -> is used to define the constant or the micro substitution 17 | #define MAX_LENGTH 255 18 | #define ENTER 13 // ASCII Value for ENTRY KEY 19 | #define TAB 9 // ASCII Value for TAB KEY 20 | #define BKSP 8 // ASCII Value for Backspace KEY 21 | #define USER_CODE 101 // access code for functions 22 | #define ADMIN_CODE 102 // access code for functions 23 | 24 | // struct for contacts record 25 | typedef struct RECORD 26 | { 27 | char firstName[MAX_LENGTH]; // uses the define subsitutor 28 | char lastName[MAX_LENGTH]; 29 | char gender; 30 | char findNum[MAX_LENGTH]; 31 | char cityName[MAX_LENGTH]; 32 | } DETAILS; 33 | 34 | // global variables 35 | char adminPassword[MAX_LENGTH] = "Admin"; // login password for ADMINISTRATOR 36 | char inputPassword[MAX_LENGTH]; 37 | char findNumber[MAX_LENGTH]; 38 | int choice = 0, len = 0; 39 | DETAILS contact; 40 | DETAILS copy; 41 | FILE *pF = NULL; 42 | 43 | // Function Prototypes or Function Declaration 44 | void infoScreen(); // introduction screen 45 | void loginPage(); // choice login type 46 | void endScreen(); // closing screen 47 | 48 | // login password & permission functions 49 | void adminLogin(); // secret password 50 | void userPanel(); 51 | void adminPanel(); 52 | 53 | // validation functions 54 | int isValidGender(char *gender); // checks for the gender input 55 | int isValidNumeric(char num[]); // checks for the phone number input 56 | int isValidName(char *name); // checks string for searchByCity & searchByName 57 | int checkNumberExistence(char *num); // checks for the input number if its exists in the database or not 58 | char *removeSpaces(char *str); // removes empty spaces from name inputs 59 | void invalidInput(int); // shows error on invalid inputs and returns them back to the panel 60 | void clearBuffer(); // clears the output screen & input buffer 61 | 62 | // operational functions 63 | void addNewContact(); 64 | void updateContact(); 65 | void deleteContact(); 66 | void deleteAllContact(); 67 | void displayContact(int); // int entryCode -> used for checking the type of user (Admin/User) 68 | void searchByName(int); 69 | void searchByNumber(int); 70 | void searchByCity(int); 71 | 72 | int main(){ 73 | 74 | infoScreen(); // starts with introduction screen & moves on to login Page 75 | return 0; 76 | } 77 | 78 | void infoScreen() 79 | { 80 | clearBuffer(); 81 | system("title Phonebook Management System"); 82 | system("color 60"); 83 | printf("\n\t\t\t\t------------------------------------------- \n"); 84 | printf("\t\t\t\t >>> Phonebook Management System <<< \n"); 85 | printf("\t\t\t\t------------------------------------------- \n\n"); 86 | printf("\t\tIt is a software application that allows users to store, organize\n\t and manage large numbers of contact records efficiently. The system is designed\n\t to have functions such as adding, updating, viewing and deleting contacts. \n\n"); 87 | printf("\t\t\t\t------------------------------------ \n"); 88 | printf("\t\t\t\t >>> Meet our project team <<< \n"); 89 | printf("\t\t\t\t------------------------------------ \n\n"); 90 | printf("\t\t\t\t\t > Ganesh Mourya \n"); 91 | printf("\t\t\t\t\t > Amit Nare \n"); 92 | printf("\t\t\t\t\t > Abrar Shaikh \n"); 93 | printf("\t\t\t\t\t > Aditya Tiwari \n"); 94 | printf("\t\t\t\t\t > Vivek Gupta \n"); 95 | printf("\t\t\t\t\t > Manish Nirala \n\n"); 96 | printf("\t\t\t\t------------------------------------ \n\n"); 97 | system("pause"); 98 | loginPage(); 99 | } 100 | 101 | void loginPage() 102 | { 103 | clearBuffer(); 104 | system("title Login Page"); 105 | printf("----------------------------------- \n"); 106 | printf(" >>> Login into system as <<< \n"); 107 | printf("----------------------------------- \n"); 108 | printf("[1] Administrator. \n"); 109 | printf("[2] User profile. \n"); 110 | printf("[3] EXIT. \n"); 111 | printf("----------------------------------- \n\n"); 112 | printf("Enter the number & Hit ENTER: "); 113 | scanf("%d",&choice); 114 | 115 | switch (choice) 116 | { 117 | case 1: 118 | adminLogin(); 119 | break; 120 | case 2: 121 | userPanel(); 122 | break; 123 | case 3: 124 | endScreen(); 125 | break; 126 | default: 127 | printf("--------------------------------------- \n"); 128 | printf("ERROR: Invalid input please try again. \n"); 129 | printf("--------------------------------------- \n"); 130 | system("pause"); 131 | loginPage(); 132 | } 133 | } 134 | 135 | void endScreen() 136 | { 137 | clearBuffer(); 138 | system("title Credits Page"); 139 | printf("\n\t\t\t\t------------------------------------------ \n"); 140 | printf("\t\t\t\t >>> Phonebook Management System <<< \n"); 141 | printf("\t\t\t\t------------------------------------------ \n\n"); 142 | printf("\t\t\t\tGitHub: https://github.com/Alkaison \n"); 143 | printf("\t\t\t\tTwitter: https://twitter.com/Alkaison \n"); 144 | printf("\t\t\t\tLinkedIn: https://linkedin.com/in/Alkaison \n\n"); 145 | printf("\t\t\t\t------------------------------------------ \n"); 146 | printf("\t\t\t\t\t\tThank You. \n"); 147 | printf("\t\t\t\t------------------------------------------ \n\n"); 148 | Sleep(1500); // pause the screen for 3 seconds 149 | exit(0); // ends the program safely 150 | } 151 | 152 | void adminLogin() 153 | { 154 | clearBuffer(); 155 | system("title Admin Login"); 156 | char ch; 157 | int i = 0; 158 | printf("----------------------------------- \n"); 159 | printf(" >>> Administrator Login <<< \n"); 160 | printf("----------------------------------- \n\n"); 161 | 162 | printf("Enter your password & Hit ENTER: "); 163 | while(1) // runs infinite times until breaked 164 | { 165 | ch = getch(); // get single character at one time & validate it 166 | if(ch == ENTER || ch == TAB){ // if ENTER or TAB Key is pressed save & break the loop 167 | inputPassword[i] = '\0'; // add NULL at the end 168 | break; 169 | } 170 | else if(ch == BKSP){ // if Backspace Key is pressed erase the last input 171 | if(i > 0){ 172 | i--; 173 | printf("\b \b"); // for backspace 174 | } 175 | } 176 | else{ 177 | inputPassword[i++] = ch; // store it at (i)th of variable 178 | printf("* \b"); // to replace password character with * 179 | } 180 | } 181 | 182 | fflush(stdin); 183 | printf("\n"); 184 | // verifies the password 185 | if(strcmp(adminPassword, inputPassword) == 0) // if both are equal then 0 is return 186 | adminPanel(); 187 | else 188 | { 189 | printf("------------------------------------------ \n"); 190 | printf("ERROR: Invalid password please try again. \n"); 191 | printf("------------------------------------------ \n"); 192 | system("pause"); 193 | loginPage(); 194 | } 195 | } 196 | 197 | void userPanel() 198 | { 199 | clearBuffer(); 200 | system("title User Panel"); 201 | printf("----------------------------------- \n"); 202 | printf("\t>>> User Panel <<< \n"); 203 | printf("----------------------------------- \n"); 204 | printf("[1] Display All Contact. \n"); 205 | printf("[2] Search By Name. \n"); 206 | printf("[3] Search By Number. \n"); 207 | printf("[4] Search By City. \n"); 208 | printf("[5] Back to Login. \n"); 209 | printf("[6] EXIT. \n"); 210 | printf("----------------------------------- \n\n"); 211 | printf("Enter the number & Hit ENTER: "); 212 | scanf("%d",&choice); 213 | 214 | switch (choice) 215 | { 216 | case 1: 217 | displayContact(USER_CODE); 218 | break; 219 | case 2: 220 | searchByName(USER_CODE); 221 | break; 222 | case 3: 223 | searchByNumber(USER_CODE); 224 | break; 225 | case 4: 226 | searchByCity(USER_CODE); 227 | break; 228 | case 5: 229 | loginPage(); 230 | break; 231 | case 6: 232 | endScreen(); 233 | break; 234 | default: 235 | printf("---------------------------------------\n"); 236 | printf("ERROR: Invalid input please try again. \n"); 237 | printf("---------------------------------------\n"); 238 | system("pause"); 239 | userPanel(); 240 | } 241 | } 242 | 243 | void adminPanel() 244 | { 245 | clearBuffer(); 246 | system("title Admin Panel"); 247 | printf("------------------------------------ \n"); 248 | printf("\t>>> Admin Panel <<< \n"); 249 | printf("------------------------------------ \n"); 250 | printf(" [1] Add New Contact. \n"); 251 | printf(" [2] Update Contact. \n"); 252 | printf(" [3] Display All Contact. \n"); 253 | printf(" [4] Search By Name. \n"); 254 | printf(" [5] Search By Number. \n"); 255 | printf(" [6] Search By City. \n"); 256 | printf(" [7] Delete Contact. \n"); 257 | printf(" [8] Delete All Contact. \n"); 258 | printf(" [9] Back to Login. \n"); 259 | printf("[10] EXIT. \n"); 260 | printf("------------------------------------ \n\n"); 261 | printf("Enter the number & Hit ENTER: "); 262 | scanf("%d",&choice); 263 | 264 | switch (choice) 265 | { 266 | case 1: 267 | addNewContact(); 268 | break; 269 | case 2: 270 | updateContact(); 271 | break; 272 | case 3: 273 | displayContact(ADMIN_CODE); 274 | break; 275 | case 4: 276 | searchByName(ADMIN_CODE); 277 | break; 278 | case 5: 279 | searchByNumber(ADMIN_CODE); 280 | break; 281 | case 6: 282 | searchByCity(ADMIN_CODE); 283 | break; 284 | case 7: 285 | deleteContact(); 286 | break; 287 | case 8: 288 | deleteAllContact(); 289 | break; 290 | case 9: 291 | loginPage(); 292 | break; 293 | case 10: 294 | endScreen(); 295 | break; 296 | default: 297 | printf("---------------------------------------\n"); 298 | printf("ERROR: Invalid input please try again. \n"); 299 | printf("---------------------------------------\n"); 300 | system("pause"); 301 | adminPanel(); 302 | } 303 | } 304 | 305 | int isValidGender(char *gender) // checks gender value through pointer 306 | { 307 | switch (*gender) 308 | { 309 | case 'M': 310 | case 'm': 311 | *gender = 'm'; 312 | return 1; 313 | case 'F': 314 | case 'f': 315 | *gender = 'f'; 316 | return 1; 317 | default: 318 | printf("--------------------------------------- \n"); 319 | printf("ERROR: Invalid gender try again later. \n"); 320 | printf("--------------------------------------- \n"); 321 | return 0; 322 | } 323 | return 0; 324 | } 325 | 326 | int isValidName(char *name) // checks name through pointer 327 | { 328 | for(int cnt=0; cnt < 255; cnt++) 329 | { 330 | if(name[cnt] == '\0') 331 | break; 332 | if(isalpha(name[cnt]) == 0) 333 | return 4; 334 | } 335 | return 0; 336 | } 337 | 338 | int isValidNumeric(char num[]) 339 | { len = 0; 340 | for(int cnt = 0; cnt < 255; cnt++) 341 | { 342 | if(num[cnt] == '\0') 343 | break; 344 | len++; 345 | if(isdigit(num[cnt]) == 0) 346 | { 347 | len = 0; 348 | return 4; 349 | } 350 | } 351 | 352 | if(len != 10) 353 | { 354 | printf("------------------------------------------ \n"); 355 | printf("ERROR: phone number must be of 10 digits. \n"); 356 | printf("------------------------------------------ \n"); 357 | return 0; 358 | } 359 | else 360 | return 1; 361 | 362 | return 0; 363 | } 364 | 365 | int checkNumberExistence(char *num) // checks for the input number if its exists in the database or not 366 | { 367 | FILE *pT = fopen("ContactList.txt","r"); 368 | 369 | while(fscanf(pT, "%s %s %c %s %s\n",copy.firstName, copy.lastName, ©.gender, copy.findNum, copy.cityName) != EOF) 370 | { 371 | if(strcmp(num, copy.findNum) == 0) 372 | { 373 | fclose(pT); 374 | return 0; 375 | } 376 | } 377 | fclose(pT); 378 | return 1; 379 | } 380 | 381 | void invalidInput(int entryCode) 382 | { 383 | printf("--------------------------------------------- \n"); 384 | printf("ERROR: Invalid input please try again later. \n"); 385 | printf("--------------------------------------------- \n"); 386 | system("pause"); 387 | (entryCode == 101) ? userPanel() : adminPanel(); 388 | } 389 | 390 | char *removeSpaces(char *str) // functions return type is (char pointer) and accepts argument as pointer 391 | { 392 | int i = 0, j = 0; 393 | while (str[i]) 394 | { 395 | if (str[i] != ' ') 396 | str[j++] = str[i]; 397 | i++; 398 | } 399 | str[j] = '\0'; 400 | strlwr(str); 401 | return str; 402 | } 403 | 404 | void clearBuffer() 405 | { 406 | system("cls"); // clears the output screen 407 | fflush(stdin); // clears the input buffers like '\n' 408 | } 409 | 410 | void addNewContact() 411 | { 412 | clearBuffer(); 413 | system("title Add New Contact"); 414 | int flag = 0; 415 | printf("------------------------------ \n"); 416 | printf(" >>> Add New Contact <<< \n"); 417 | printf("------------------------------ \n\n"); 418 | pF = fopen("ContactList.txt", "ab+"); 419 | 420 | // checks if the txt file exists or not 421 | if(pF != NULL) 422 | { 423 | printf("Enter the first name: "); 424 | gets(contact.firstName); 425 | 426 | printf("Enter the last name: "); 427 | gets(contact.lastName); 428 | 429 | printf("Enter the city name: "); 430 | gets(contact.cityName); 431 | 432 | printf("Enter the gender [M/F]: "); 433 | scanf(" %c",&contact.gender); 434 | fflush(stdin); 435 | 436 | printf("Enter the phone number [+91]: "); 437 | gets(contact.findNum); 438 | printf("\n"); 439 | 440 | removeSpaces(contact.findNum); 441 | // validates gender & phoneNumber inputs to prevent storing invalid data into files 442 | if(isValidGender(&contact.gender)) 443 | { 444 | if(isValidNumeric(contact.findNum) == 1) 445 | { 446 | if(checkNumberExistence(contact.findNum)) 447 | { 448 | removeSpaces(contact.firstName); 449 | removeSpaces(contact.lastName); 450 | removeSpaces(contact.cityName); 451 | fprintf(pF, "%s %s %c %s %s\n", contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 452 | printf("---------------------------------------------- \n"); 453 | printf("Success: Contact details added in the record. \n"); 454 | printf("---------------------------------------------- \n"); 455 | } 456 | else 457 | { 458 | printf("---------------------------------------------------- \n"); 459 | printf("ERROR: Phone number already exists in the database. \n"); 460 | printf("---------------------------------------------------- \n"); 461 | } 462 | } 463 | else 464 | flag = 1; 465 | } 466 | } 467 | else 468 | printf("ERROR: Unable to locate or open the file. \n"); 469 | 470 | fclose(pF); 471 | if(flag == 1 && len == 0) // if the phoneNumber entered is invalid it wil execute 472 | { 473 | printf("------------------------------------------------------- \n"); 474 | printf("ERROR: Invalid input for phone number try again later. \n"); 475 | printf("------------------------------------------------------- \n"); 476 | } 477 | system("pause"); 478 | adminPanel(); 479 | } 480 | 481 | void updateContact() 482 | { 483 | clearBuffer(); 484 | system("title Update Contact"); 485 | char confirmDelete[MAX_LENGTH]; 486 | int flag = 0, counter = 1; 487 | 488 | printf("----------------------------- \n"); 489 | printf(" >>> Update Contact <<< \n"); 490 | printf("----------------------------- \n\n"); 491 | printf("Enter the phone number to update [+91]: "); 492 | gets(findNumber); 493 | printf("\n"); 494 | 495 | if(isValidNumeric(findNumber) == 4) // checks for each character of the number 496 | invalidInput(ADMIN_CODE); 497 | 498 | pF = fopen("ContactList.txt", "r"); 499 | FILE *pT = fopen("temporary.txt", "w"); 500 | 501 | while(fscanf(pF, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF) 502 | { 503 | if(strcmp(findNumber, contact.findNum) == 0) 504 | { 505 | // if there two contacts will same phoneNumber it will pop alert message 506 | if(counter >= 2) 507 | printf("\n\t\tALERT: We found another contact with the same phone number.\n\t\t\tPlease review it too.\n\n"); 508 | 509 | printf("\t\t|===============================================================| \n"); 510 | printf("\t\t|ID| \tName\t\t| Gender | Phone Number\t| City Name\t| \n"); 511 | printf("\t\t|===============================================================| \n"); 512 | printf("\t\t| %d| %s %s \t| %c |\t %s \t| %s \t| \n\n", counter++, contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 513 | printf("--------------------------------------------------- \n"); 514 | printf("> Contact Found in records. Enter the new details. \n"); 515 | printf("--------------------------------------------------- \n"); 516 | fflush(stdin); 517 | printf("Enter the first name: "); 518 | gets(copy.firstName); 519 | 520 | printf("Enter the last name: "); 521 | gets(copy.lastName); 522 | 523 | printf("Enter the city name: "); 524 | gets(copy.cityName); 525 | 526 | fflush(stdin); 527 | printf("\n"); 528 | 529 | printf("Type `CONFIRM` to update this details: "); 530 | gets(confirmDelete); 531 | if(strcmp(confirmDelete, "CONFIRM") == 0) 532 | { 533 | // validates everything and fetchs into file 534 | removeSpaces(copy.firstName); 535 | removeSpaces(copy.lastName); 536 | removeSpaces(copy.cityName); 537 | printf("\nProcessing . . . \n\n"); 538 | fprintf(pT, "%s %s %c %s %s\n",copy.firstName, copy.lastName, contact.gender, contact.findNum, copy.cityName); 539 | flag = 2; 540 | } 541 | else 542 | { 543 | flag = 1; 544 | fprintf(pT, "%s %s %c %s %s\n", contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 545 | } 546 | } 547 | else 548 | fprintf(pT, "%s %s %c %s %s\n", contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 549 | } 550 | fclose(pF); 551 | fclose(pT); 552 | 553 | // only perform update process only if the user is ready for it 554 | if(flag == 1 || flag == 2) 555 | { 556 | pF = fopen("ContactList.txt", "w"); 557 | pT = fopen("temporary.txt", "r"); 558 | 559 | while(fscanf(pT, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF) 560 | fprintf(pF, "%s %s %c %s %s\n", contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 561 | 562 | fclose(pF); 563 | fclose(pT); 564 | } 565 | 566 | pT = fopen("temporary.txt", "w"); 567 | fclose(pT); 568 | 569 | if(flag == 0 && len == 10) // return different error messages upon the flag value 570 | { 571 | printf("----------------------------------------- \n"); 572 | printf("> No contacts found matching your input. \n"); 573 | printf("----------------------------------------- \n"); 574 | } 575 | else if(flag == 1) 576 | { 577 | printf("----------------------------------------- \n"); 578 | printf("> ERROR: Invalid message try again later. \n"); 579 | printf("----------------------------------------- \n"); 580 | } 581 | else if(flag == 2) 582 | { 583 | printf("----------------------------- \n"); 584 | printf("> Success: contact updated. \n"); 585 | printf("----------------------------- \n"); 586 | } 587 | 588 | system("pause"); 589 | adminPanel(); 590 | } 591 | 592 | void deleteContact() 593 | { 594 | clearBuffer(); 595 | system("title Delete Contact"); 596 | char confirmDelete[MAX_LENGTH]; 597 | int flag = 0, counter = 1; 598 | 599 | printf("----------------------------- \n"); 600 | printf(" >>> Delete Contact <<< \n"); 601 | printf("----------------------------- \n\n"); 602 | printf("Enter the phone number to delete [+91]: "); 603 | gets(findNumber); 604 | printf("\n"); 605 | 606 | if(isValidNumeric(findNumber) == 4) 607 | invalidInput(ADMIN_CODE); 608 | 609 | pF = fopen("ContactList.txt", "r"); 610 | FILE *pT = fopen("temporary.txt", "w"); 611 | 612 | while(fscanf(pF, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF) 613 | { 614 | if(strcmp(findNumber, contact.findNum) == 0) 615 | { 616 | if(counter >= 2) 617 | printf("\n\t\tALERT: We found another contact with the same phone number.\n\t\t\tPlease review it too.\n\n"); 618 | 619 | printf("\t\t|===============================================================| \n"); 620 | printf("\t\t|ID| \tName\t\t| Gender | Phone Number\t| City Name\t| \n"); 621 | printf("\t\t|===============================================================| \n"); 622 | printf("\t\t| %d| %s %s \t| %c |\t %s \t| %s \t| \n", counter++, contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 623 | 624 | fflush(stdin); 625 | flag = 1; 626 | printf("\nType `CONFIRM` to delete this contact: "); 627 | gets(confirmDelete); 628 | 629 | if(strcmp(confirmDelete, "CONFIRM") == 0) 630 | { 631 | printf("\n\t\tProcessing . . . \n\n"); 632 | flag = 2; 633 | } 634 | else 635 | { 636 | printf("\n\t\tProcessing . . . \n\n"); 637 | fprintf(pT, "%s %s %c %s %s\n", contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 638 | } 639 | } 640 | else 641 | fprintf(pT, "%s %s %c %s %s\n", contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 642 | } 643 | fclose(pF); 644 | fclose(pT); 645 | 646 | if(flag == 1 || flag == 2) 647 | { 648 | pF = fopen("ContactList.txt", "w"); 649 | pT = fopen("temporary.txt", "r"); 650 | 651 | while(fscanf(pT, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF) 652 | fprintf(pF, "%s %s %c %s %s\n", contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 653 | 654 | fclose(pF); 655 | fclose(pT); 656 | } 657 | 658 | pT = fopen("temporary.txt", "w"); 659 | fclose(pT); 660 | 661 | // show the messaage according to the operations perform 662 | if(flag == 0 && len == 10) 663 | { 664 | printf("----------------------------------------- \n"); 665 | printf("> No contacts found matching your input. \n"); 666 | printf("----------------------------------------- \n"); 667 | } 668 | else if(flag == 1) 669 | { 670 | printf("----------------------------------------- \n"); 671 | printf("> ERROR: Invalid message try again later. \n"); 672 | printf("----------------------------------------- \n"); 673 | } 674 | else if(flag == 2) 675 | { 676 | printf("----------------------------- \n"); 677 | printf("> Success: contact deleted. \n"); 678 | printf("----------------------------- \n"); 679 | } 680 | 681 | system("pause"); 682 | adminPanel(); 683 | } 684 | 685 | void deleteAllContact() 686 | { 687 | clearBuffer(); 688 | system("title Delete All Contact"); 689 | char confirmDelete[MAX_LENGTH]; 690 | printf("--------------------------------- \n"); 691 | printf(" >>> Delete All Contact <<< \n"); 692 | printf("--------------------------------- \n\n"); 693 | printf("Type `CONFIRM` to delete all the contact. \n"); 694 | printf("Message: "); 695 | gets(confirmDelete); 696 | printf("\n"); 697 | 698 | // checks for the confirmation message 699 | choice = strcmp(confirmDelete, "CONFIRM"); 700 | if(choice == 0) 701 | { 702 | pF = fopen("ContactList.txt", "w"); // erases everything from file and then save it 703 | fclose(pF); 704 | printf("------------------------------------------- \n"); 705 | printf("Success: All contact details are deleted. \n"); 706 | printf("------------------------------------------- \n"); 707 | } 708 | else 709 | { 710 | printf("----------------------------------------- \n"); 711 | printf("ERROR: Invalid message try again later. \n"); 712 | printf("----------------------------------------- \n"); 713 | } 714 | 715 | system("pause"); 716 | adminPanel(); 717 | } 718 | 719 | void displayContact(int entryCode) 720 | { 721 | clearBuffer(); 722 | int counter = 1; 723 | system("title Display All Contact"); 724 | printf("\n\n\t\t\t\t---------------------------- \n"); 725 | printf("\t\t\t\t >>> Contacts List <<< \n"); 726 | printf("\t\t\t\t---------------------------- \n\n"); 727 | pF = fopen("ContactList.txt", "r"); 728 | 729 | if(fscanf(pF, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF) 730 | { 731 | printf("\t\t|===============================================================| \n"); 732 | printf("\t\t|ID| \tName\t\t| Gender | Phone Number\t| City Name\t| \n"); 733 | printf("\t\t|===============================================================| \n"); 734 | 735 | do 736 | { 737 | printf("\t\t| %d| %s %s \t| %c |\t %s \t| %s \t| \n", counter++, contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 738 | 739 | } while(fscanf(pF, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF); 740 | 741 | printf("\t\t|===============================================================| \n\n"); 742 | } 743 | else 744 | printf(" ERROR: Either we are unable to locate the ContactList.txt file or\n\t there are no contacts saved in the file. \n\n"); 745 | 746 | fclose(pF); 747 | system("pause"); 748 | (entryCode == 101) ? userPanel() : adminPanel(); 749 | } 750 | 751 | void searchByName(int entryCode) 752 | { 753 | clearBuffer(); 754 | system("title Search By Name"); 755 | char findName[MAX_LENGTH]; 756 | int compare = 1, flag = 0, counter = 1; 757 | 758 | printf("----------------------------- \n"); 759 | printf(" >>> Search By Name <<< \n"); 760 | printf("----------------------------- \n\n"); 761 | 762 | printf("Enter the first or last name: "); 763 | gets(findName); 764 | 765 | // if the input has space at end remove it 766 | if(findName[strlen(findName) - 1] == ' ') 767 | findName[strlen(findName) - 1] = '\0'; 768 | 769 | printf("\n"); 770 | strlwr(findName); 771 | 772 | if(isValidName(findName) == 4) 773 | invalidInput(entryCode); 774 | 775 | pF = fopen("ContactList.txt", "r"); 776 | while(fscanf(pF, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF) 777 | { 778 | compare = strcmp(findName, contact.firstName); 779 | 780 | if(compare != 0) 781 | compare = strcmp(findName, contact.lastName); 782 | 783 | if(compare == 0) 784 | { 785 | if(counter == 1) 786 | { 787 | printf("\t\t|===============================================================| \n"); 788 | printf("\t\t|ID| \tName\t\t| Gender | Phone Number\t| City Name\t| \n"); 789 | printf("\t\t|===============================================================| \n"); 790 | } 791 | printf("\t\t| %d| %s %s \t| %c |\t %s \t| %s \t| \n", counter++, contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 792 | flag++; 793 | } 794 | } 795 | fclose(pF); 796 | 797 | if(counter > 1) 798 | printf("\t\t|===============================================================| \n\n"); 799 | 800 | if(flag == 0) 801 | { 802 | printf("----------------------------------------- \n"); 803 | printf("> No contacts found matching your input. \n"); 804 | printf("----------------------------------------- \n"); 805 | } 806 | system("pause"); 807 | (entryCode == 101) ? userPanel() : adminPanel(); 808 | } 809 | 810 | void searchByNumber(int entryCode) 811 | { 812 | clearBuffer(); 813 | system("title Search By Number"); 814 | int flag = 0, counter = 1; 815 | 816 | printf("------------------------------- \n"); 817 | printf(" >>> Search By Number <<< \n"); 818 | printf("------------------------------- \n\n"); 819 | 820 | printf("Enter the phone number [+91]: "); 821 | gets(findNumber); 822 | 823 | printf("\n"); 824 | if(isValidNumeric(findNumber) == 4) 825 | invalidInput(entryCode); 826 | if(len != 10) 827 | flag++; 828 | 829 | pF = fopen("ContactList.txt", "r"); 830 | while(fscanf(pF, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF) 831 | { 832 | if(strcmp(findNumber, contact.findNum) == 0) 833 | { 834 | if(counter == 1) 835 | { 836 | printf("\t\t|===============================================================| \n"); 837 | printf("\t\t|ID| \tName\t\t| Gender | Phone Number\t| City Name\t| \n"); 838 | printf("\t\t|===============================================================| \n"); 839 | } 840 | printf("\t\t| %d| %s %s \t| %c |\t %s \t| %s \t| \n", counter++, contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 841 | flag++; 842 | } 843 | } 844 | fclose(pF); 845 | 846 | if(counter > 1) 847 | printf("\t\t|===============================================================| \n\n"); 848 | 849 | if(flag == 0) 850 | { 851 | printf("----------------------------------------- \n"); 852 | printf("> No contacts found matching your input. \n"); 853 | printf("----------------------------------------- \n"); 854 | } 855 | system("pause"); 856 | (entryCode == 101) ? userPanel() : adminPanel(); // get them back to there panel according to entrycode 857 | } 858 | 859 | void searchByCity(int entryCode) 860 | { 861 | clearBuffer(); 862 | system("title Search By City Name"); 863 | char findCity[MAX_LENGTH]; 864 | int compare = 1, flag = 0, counter = 1; 865 | 866 | printf("----------------------------- \n"); 867 | printf(" >>> Search By City <<< \n"); 868 | printf("----------------------------- \n\n"); 869 | 870 | printf("Enter the city name: "); 871 | gets(findCity); 872 | 873 | // if the input has space at end remove it 874 | if(findCity[strlen(findCity) - 1] == ' ') 875 | findCity[strlen(findCity) - 1] = '\0'; 876 | 877 | printf("\n"); 878 | strlwr(findCity); 879 | 880 | if(isValidName(findCity) == 4) 881 | invalidInput(entryCode); 882 | 883 | pF = fopen("ContactList.txt", "r"); 884 | while(fscanf(pF, "%s %s %c %s %s\n",contact.firstName, contact.lastName, &contact.gender, contact.findNum, contact.cityName) != EOF) 885 | { 886 | compare = strcmp(findCity, contact.cityName); 887 | 888 | if(compare == 0) 889 | { 890 | if(counter == 1) 891 | { 892 | printf("\t\t|===============================================================| \n"); 893 | printf("\t\t|ID| \tName\t\t| Gender | Phone Number\t| City Name\t| \n"); 894 | printf("\t\t|===============================================================| \n"); 895 | } 896 | printf("\t\t| %d| %s %s \t| %c |\t %s \t| %s \t| \n", counter++, contact.firstName, contact.lastName, contact.gender, contact.findNum, contact.cityName); 897 | flag++; 898 | } 899 | } 900 | fclose(pF); 901 | 902 | if(counter > 1) 903 | printf("\t\t|===============================================================| \n\n"); 904 | 905 | if(flag == 0) 906 | { 907 | printf("----------------------------------------- \n"); 908 | printf("> No contacts found matching your input. \n"); 909 | printf("----------------------------------------- \n"); 910 | } 911 | system("pause"); 912 | (entryCode == 101) ? userPanel() : adminPanel(); 913 | } --------------------------------------------------------------------------------