#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<windows.h>
#include<string.h>
// Define KeyWords
#define ENTER 13
#define TAB 9
#define BKSP 8
// Function ProtoType
void password(void);
void menu(void);
void add(void);
void search(void);
void modify(void);
void list(void);
void delete(void);
void end(void);
void main(){
password();
}
//Explained the password function in proper detailed.
void password()
{
system("cls");
char pwd[255];
char code[255] = {"Alkaison"};
int i = 0;
char ch;
printf("Enter your password. Hit ENTER to confirm. \n");
printf("Password:");
while(1)
{
ch = getch(); // get key
if(ch == ENTER || ch == TAB)
{
pwd[i] = '\0';
break;
}
else if(ch == BKSP)
{
if(i > 0)
{
i--;
printf("\b \b"); // for backspace
}
}
else
{
pwd[i++] = ch;
printf("* \b"); // to replace password character with *
}
}
// printf("\n\nPassword:%s\nLength:%d\n\n", pwd, i); -- prints the user input & lenght of string
// verifies the password
if(strcmp(code, pwd) == 0)
{
printf("\nCorrect Password!");
Sleep(2000);
menu();
}
else
{
printf("\nInvaild Password!");
Sleep(2000);
password();
}
}
void menu()
{
//clears the terminal screen
system("cls");
label1:
//clears the input stream - prevents the program from going into infinite loop
fflush(stdin);
printf(">>> Phone Book Main Menu <<< \n");
printf("> 1. Add Record\n");
printf("> 2. Search Record\n");
printf("> 3. Modify Record\n");
printf("> 4. List Record\n");
printf("> 5. Delete Record\n");
printf("> 6. Close the Phone Book \n\n");
int input;
printf("Please enter a number to proceed: ");
scanf("%d",&input);
switch (input)
{
case 1:
add();
break;
case 2:
search();
break;
case 3:
modify();
break;
case 4:
list();
break;
case 5:
delete();
break;
case 6:
end();
break;
default:
printf("\nXXX - Invaild input - XXX\n\n");
goto label1;
break;
}
}
void add()
{
label1:
//clears the input stream - prevents the program from going into infinite loop
fflush(stdin);
system("cls");
//opening file -- ab+ -- it will create the file if its not there, also used for writing.
FILE *pF = fopen("record.txt", "ab+");
char name[255];
char address[255];
char mail[255];
double number;
if(pF != NULL)
{
printf("Enter Name: ");
gets(name);
printf("Enter Address (City): ");
gets(address);
printf("Enter Mail-ID: ");
gets(mail);
printf("Enter Phone No.: ");
scanf("%lf",&number);
fprintf(pF, "%s %s %s %.0lf \n", name, address, mail, number);
}
else
printf("Unable to open/locate the file.");
//closes the file
fclose(pF);
fflush(stdin);
//retry screen
char input;
printf("Do you wanna enter more records [y/N]: ");
scanf(" %c",&input);
if(input == 'y' || input=='Y')
goto label1;
else if(input=='n' || input=='N')
{
printf("\nRedirecting to main menu.");
Sleep(2000);
menu();
}
else
{
printf("\nInvaild input. Redirecting to main menu.");
Sleep(2000);
menu();
}
}
void search()
{
label2:
system("cls");
fflush(stdin);
FILE *pF = fopen("record.txt", "r");
char name[255];
char address[255];
char mail[255];
double number;
int flag=0;
int compare;
char find[255];
printf("Enter the name of the person you want to see the detail: ");
gets(find);
while(fscanf(pF, "%s %s %s %lf \n", name, address, mail, &number) != EOF)
{
//strcmp(variable, variable1) -- if both the strings are equal then it will return 0 otherwise a random number.
compare = strcmp(find, name);
if(compare == 0)
{
printf("\n>>> Record Found <<< \n\n");
printf("> Name: %s \n", name);
printf("> Address: %s \n", address);
printf("> Mail ID: %s \n", mail);
printf("> Phone No.: %.0lf \n", number);
flag = 1;
}
}
fclose(pF);
if(flag == 0)
printf("\n>>> Record Not Found <<< \n");
fflush(stdin);
char input;
printf("\nDo you wanna search for more records [y/N]: ");
scanf(" %c",&input);
if(input == 'y' || input=='Y')
goto label2;
else if(input=='n' || input=='N')
{
printf("\nRedirecting to main menu.");
Sleep(2000);
menu();
}
else
{
printf("\nInvaild input. Redirecting to main menu.");
Sleep(2000);
menu();
}
}
void modify()
{
system("cls");
fflush(stdin);
//opening main record file & a temporary file s
FILE *pF = fopen("record.txt", "r");
FILE *pTemp = fopen("temporary.txt", "a");
char name[255], address[255], mail[255];
char name1[255], address1[255], mail1[255];
double number, number1;
int compare, flag=0;
printf("Enter the name of the person you want to see the detail: ");
gets(name1);
fflush(stdin);
system("cls");
while(fscanf(pF, "%s %s %s %lf \n", name, address, mail, &number) != EOF)
{
compare = strcmp(name1, name);
if(compare == 0)
{
printf("-------------------------------\n");
printf(">>> Record Modification <<< \n");
printf("-------------------------------\n\n");
printf("Enter Name: ");
gets(name1);
printf("Enter Address (City): ");
gets(address1);
printf("Enter Mail-ID: ");
gets(mail1);
printf("Enter Phone No.: ");
scanf("%lf",&number1);
fprintf(pTemp, "%s %s %s %.0lf \n", name1, address1, mail1, number1);
flag = 1;
}
else
fprintf(pTemp, "%s %s %s %.0lf \n", name, address, mail, number);
}
if(flag == 0)
{
printf("-------------------------------\n");
printf(">>> Record Not Found <<< \n");
printf("-------------------------------\n\n");
}
fclose(pF);
fclose(pTemp);
//deletes everything from main record file
pF = fopen("record.txt", "w");
fclose(pF);
pF = fopen("record.txt", "a");
pTemp = fopen("temporary.txt", "r");
//copies records from temporary file to main record file
while (fscanf(pTemp, "%s %s %s %lf \n", name, address, mail, &number) != EOF)
{
fprintf(pF, "%s %s %s %.0lf \n", name, address, mail, number);
}
fclose(pF);
fclose(pTemp);
//deletes everything from temporary file
pTemp = fopen("temporary.txt", "w");
fclose(pTemp);
printf("\n\nProcessing your changes....");
Sleep(3000);
menu();
}
void list()
{
system("cls");
FILE *pF = fopen("record.txt", "r");
char name[255];
char address[255];
char mail[255];
double number;
//lists all the records from main record files
while(fscanf(pF, "%s %s %s %lf \n", name, address, mail, &number) != EOF)
{
printf("-------------------------------\n");
printf("> Name: %s \n", name);
printf("> Address: %s \n", address);
printf("> Mail-ID: %s \n", mail);
printf("> Phone No.: %.0lf \n", number);
printf("-------------------------------\n\n\n");
}
fclose(pF);
printf("Press any key to get back to main menu.\n");
getch();
menu();
}
void delete()
{
system("cls");
FILE *pF = fopen("record.txt", "r");
FILE *pTemp = fopen("temporary.txt", "a");
char name[255], name1[255], address[255], mail[255];
d
没有合适的资源?快使用搜索试试~ 我知道了~
C语言编写的项目源码合集
共72个文件
c:51个
png:21个
需积分: 1 4 下载量 92 浏览量
2023-08-09
14:47:22
上传
评论
收藏 264KB ZIP 举报
温馨提示
10个有趣的C语言项目创意以及相应的源代码。这些项目适合初学者和计算机科学与工程(CSE)、信息技术(IT)、计算应用学士(BCA)等专业的一年级学生使用。
资源推荐
资源详情
资源评论
收起资源包目录
C语言项目源码合集.zip (72个子文件)
运行截图
UnitConverter-6.png 11KB
PhoneBook-5.png 13KB
UnitConverter-4.png 15KB
PhoneBook-7.png 12KB
Calculator-1.png 5KB
PassProtector-1.png 7KB
FunHack-2.png 11KB
FunHack-3.png 43KB
PhoneBook-6.png 7KB
Calculator-2.png 9KB
PhoneBook-8.png 10KB
PhoneBook-1.png 7KB
FunHack-1.png 6KB
PhoneBook-4.png 10KB
UnitConverter-3.png 12KB
PhoneBook-3.png 24KB
UnitConverter-5.png 9KB
UnitConverter-1.png 14KB
PhoneBook-2.png 10KB
PassProtector-2.png 7KB
UnitConverter-2.png 12KB
College_Programs
QuotientRemainder.c 378B
Even_DoWhile.c 252B
Table_Loops.c 203B
EligibleForVoting.c 290B
Smallest_Number.c 650B
GoTo_Program.c 270B
Asciii_Value.c 168B
EligibleForMarriage.c 725B
Month_Days_Switch.c 447B
Vowel_Switch.c 338B
WeekDays_Switch.c 580B
SimpleInterest.c 418B
EvenOdd_If_Else.c 220B
Value_Address.c 140B
ArmsStrong_Number.c 485B
StudentGrade.c 808B
Pattern-4.c 156B
Greatest_Number.c 592B
Sum_Number_Digits.c 371B
AreaOfCircle.c 300B
EvenOdd_Ternary_Operator.c 199B
Odd_WhileLoop.c 196B
Calculator_Switch.c 1KB
Pattern-3.c 157B
Pattern-2.c 152B
Factorial_Loops.c 286B
SquareCubeNumber.c 259B
Zero_User_Input_Loop.c 524B
Male_Female_MF.c 286B
Fibonacci_Loops.c 332B
Palindrome_Number.c 559B
Pattern-1.c 153B
Convert_RS_To_Paisa.c 201B
SwapWithOnlyTwoNumbers.c 353B
LeapYear.c 289B
Print_1_To_10.c 122B
Positive_Negative_Number.c 342B
HelloWorld.c 77B
PrintName_10_Times.c 129B
A_To_Z_Loops.c 243B
Baby_School_Adult_Age_Counter.c 735B
TakeUserInputAndDisplay.c 164B
AreaOfRectangle.c 287B
SumTwoNumbers.c 260B
Break_Continue.c 272B
DivisibleBy_3_7.c 523B
Projects
FunHack.c 840B
PassProtector.c 1005B
UnitConverter.c 4KB
Calculator.c 1KB
PhoneBook.c 10KB
共 72 条
- 1
资源评论
竹山全栈
- 粉丝: 2133
- 资源: 261
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功