-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_base.c
More file actions
152 lines (112 loc) · 3.55 KB
/
data_base.c
File metadata and controls
152 lines (112 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
// #include <errno.h>
#include <stdbool.h>
// Error handle
#define try bool __HadError=false;
#define catch(x) ExitJmp:if(__HadError)
#define throw(x) {__HadError=true;goto ExitJmp;}
// Colors
#define RED "\x1B[31m"
#define GREEN "\x1B[32m"
#define YELLOW "\x1B[33m"
#define BLUE "\x1B[34m"
#define MAGENTA "\x1B[35m"
#define CYN "\x1B[36m"
#define WHITE "\x1B[37m"
#define RESET "\x1B[0m"
int main(){
//clear screen
// try{
// system("clear 2>null");
// throw();
// }
// catch() {
// system("cls 2>null");
// }
// variables
char ask;
char name[30];
char l_name[35];
int *age ;
int *number;
char loc[200];
char pass[100];
char bul;
FILE *file;
//allocate memory
age = (int*)calloc(40 , sizeof(int));
number = (int*)calloc(80 , sizeof(int));
// start
// printf(GREEN "======================= welcome to data base app ===========================" RESET);
// printf("\n\nWant to find User or Create (f/c) : ");
// scanf("%c" , &ask);
// while (getchar() != '\n')
// printf("");
// if (ask == 'c'){
printf(GREEN "\n\nEnter user name : " RESET);
fgets(name , sizeof(name) , stdin);
printf(GREEN "\nEnter last name : " RESET);
fgets(l_name , sizeof(l_name) , stdin);
printf(GREEN "\nEnter User age : " RESET);
scanf("%d" , &age);
printf(GREEN "\nEnter User phone number : " RESET);
scanf("%d" , &number);
while (getchar() != '\n')
printf("");
printf(GREEN "\nEnter User address : " RESET);
fgets(loc , sizeof(loc) , stdin);
printf(GREEN "\nEnter User pass : " RESET);
scanf("%s" , &pass);
printf(RED "\n==========================================" RESET);
printf("\nYou entered for user name is >> %sYou entered for last name is >> %sUser pass is >> %s" , name ,l_name , pass);
printf(RED "\n==========================================" RESET);
while (getchar () != '\n')
printf("");
printf(YELLOW "\n\nWant to save it (y/n) : " RESET);
bul = getchar();
if(bul == 'y' | bul == 'Y'){
file = fopen("User.txt" , "a");
fprintf(file , "\n=====================================================\n");
fprintf(file , "Username : %s" , name);
fprintf(file , "Last name : %s" , l_name);
fprintf(file , "Age : %d" , age);
fprintf(file , "\nNumber : %d" , number);
fprintf(file , "\nAddress : %s" , loc);
fprintf(file , "Password : %s" , pass);
fclose(file);
printf("\nsaved in User.txt file");
}
else if (bul == 'n' | bul == 'N')
{
exit(1);
}
// if ask c
//variable
// FILE *find;
// char f_user[25];
// char pwd[25];
// if (ask == 'f'){
// printf("\nWhich user want to search : ");
// fgets(f_user , sizeof(f_user) , stdin);
// find = fopen("User.txt" , "r");
// if (find == NULL){
// printf("You didnt add any user to file");
// exit(1);
// }
// if(fscanf(find , "%s" ,f_user)){
// printf("\nEnter password : ");
// fgets(pwd , sizeof(pwd) , stdin);
// if(fscanf(find , "%s" , pwd)){
// printf("hey");
// }
// }
// else{
// printf("couldnt find any user !");
// }
// fclose(find);
//if ask f
return 0;
}//main