-
Notifications
You must be signed in to change notification settings - Fork 0
/
error-checking.c
157 lines (148 loc) · 3.02 KB
/
error-checking.c
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
153
154
155
156
157
#include <ctype.h>
#include <string.h>
#include "lib/error-checking.h"
#include <stdio.h>
int check_id(char (*id)[11])
{
if(strlen(*id)!=9)
{
printf("Mistake! The size of ID should be 9\n"); //size error
return 1;
}
for (int i = 0; i < 9; i++) {
if (!(isdigit((*id)[i]))) { //error check (it should be digits)
printf("Mistake! ID should consists from digits\n");
return 1;
}
}
return 0;
}
int check_parent(char (*name)[25])
{
if(strlen(*name)>25)
{
printf("You exceeded the limit\n");
return 1;
}
for (int i=0; i < strlen(*name); i++) {
if (!(isalpha((*name)[i])) && (*name)[i]!='_' ) {
printf("Mistake! Wrong name format\n");
return 1;
}
}
int sig=0;
for (int i=0; i < strlen(*name); i++) {
if((*name)[i]=='_')sig++;
}
if(sig!=1)
{
printf("Mistake! Wrong name format\n");
return 1;
}
char ch = (*name)[0]; //First character
if ((!isupper(ch)))
{
printf("Mistake! Wrong name format\n");
return 1;
}
return 0;
}
int check_name(char (*name)[60])
{
if(strlen(*name)>59)
{
printf("You exceeded the limit\n");
return 1;
}
for (int i=0; i < strlen(*name); i++) {
if (!(isalpha((*name)[i])) && (*name)[i]!='_' ) {
printf("Mistake! Wrong name format\n");
return 1;
}
}
int sig=0;
for (int i=0; i < strlen(*name); i++) {
if((*name)[i]=='_')sig++;
}
if(sig!=1)
{
printf("Mistake! Wrong name format\n");
return 1;
}
char ch = (*name)[0]; //First character
if ((!isupper(ch)))
{
printf("Mistake! Wrong name format\n");
return 1;
}
return 0;
}
int check_faculty(char (*faculty)[25])
{
if(strlen(*faculty)>24)
{
printf("You exceeded the limit\n");
return 1;
}
if(strcmp(*faculty,"SPIA")==0 || strcmp(*faculty,"SITE")==0 || strcmp(*faculty,"SB")==0)return 0;
else {
printf("There is not such faculty!\n");
return 1;
}
}
int check_major(char (*major)[25])
{
if(strlen(*major)>24)
{
printf("You exceeded the limit\n");
return 1;
}
if(strcmp(*major,"CS")==0 || strcmp(*major,"IT")==0 || strcmp(*major,"CE")==0 || strcmp(*major,"BA")==0 || strcmp(*major,"EC")==0 || strcmp(*major,"FC")==0 || strcmp(*major,"MBA")==0 || strcmp(*major,"Law")==0 || strcmp(*major,"PA")==0 || strcmp(*major,"IS")==0 || strcmp(*major,"CDM")==0)return 0;
else{
printf("There is not such major!\n");
return 1;
}
}
int check_contact(char (*number)[20])
{
if(strlen(*number)>20)
{
printf("You exceeded the limit\n");
return 1;
}
if((*number)[0]!='+')
{
printf("Wrong mobile number format\n");
return 1;
}
if(strlen(*number)>16)
{
printf("Wrong size of mobile number\n");
return 1;
}
//ToDo update by using database of country codes
return 0;
}
int check_gpa(double x)
{
if(x>4.0)
{
printf("Mistake! Max GPA is 4.0!\n");
return 1;
}
else if(x<-1.0)
{
printf("Mistake! Min GPA is -1.0 if GPA is unknown!\n");
return 1;
}
return 0;
}
int check_numsubj(int x)
{
if(x>40)
{
printf("You exceeded the limit\n");
return 1;
}
else return 0;
}