author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Fri, 03 Oct 2014 13:14:34 +0100 | |
changeset 192 | 2cb42412f3fd |
parent 105 | 40c51038c9e4 |
child 211 | e6e160c7ea33 |
permissions | -rw-r--r-- |
105
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
int match(char *s1, char *s2) { |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
while( *s1 != '\0' && *s2 != '\0' && *s1 == *s2 ){ |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
s1++; s2++; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
} |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
return( *s1 - *s2 ); |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
6 |
} |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
|
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
void welcome() { printf("Welcome to the Machine!\n"); exit(0); } |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
void goodbye() { printf("Invalid identity, exiting!\n"); exit(1); } |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
|
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
main(){ |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
char name[8]; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
char pw[8]; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
|
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
printf("login: "); |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
16 |
get_line(name); |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
17 |
printf("password: "); |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
get_line(pw); |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
19 |
|
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
20 |
if(match(name, pw) == 0) |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
welcome(); |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
22 |
else |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
23 |
goodbye(); |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
} |