equal
deleted
inserted
replaced
|
1 #include <string.h> |
|
2 #include <stdio.h> |
|
3 #include <stdlib.h> |
|
4 |
|
5 // Since gets() is insecure and produces lots |
|
6 // of warnings, thereofre I use my own input |
|
7 // function instead. |
|
8 void get_line(char *dst) { |
|
9 char buffer[8]; |
|
10 int i = 0; |
|
11 char ch; |
|
12 while ((ch = getchar()) != '\n') { |
|
13 buffer[i++] = ch; |
|
14 } |
|
15 buffer[i] = '\0'; |
|
16 strcpy(dst, buffer); |
|
17 } |
|
18 |
1 int match(char *s1, char *s2) { |
19 int match(char *s1, char *s2) { |
2 while( *s1 != '\0' && *s2 != '\0' && *s1 == *s2 ){ |
20 while(*s1 != '\0' && *s2 != '\0' && *s1 == *s2){ |
3 s1++; s2++; |
21 s1++; s2++; |
4 } |
22 } |
5 return( *s1 - *s2 ); |
23 return( *s1 - *s2 ); |
6 } |
24 } |
7 |
25 |
8 void welcome() { printf("Welcome to the Machine!\n"); exit(0); } |
26 void welcome() { printf("Welcome!\n"); exit(0); } |
9 void goodbye() { printf("Invalid identity, exiting!\n"); exit(1); } |
27 void goodbye() { printf("Wrong identity, exiting!\n"); exit(1); } |
10 |
28 |
11 main(){ |
29 int main(){ |
12 char name[8]; |
30 char name[8]; |
13 char pw[8]; |
31 char pw[8]; |
14 |
32 |
15 printf("login: "); |
33 printf("login: "); |
16 get_line(name); |
34 get_line(name); |