author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 26 Sep 2017 12:35:32 +0100 | |
changeset 537 | 72dbf4154173 |
parent 216 | 38718062709a |
permissions | -rw-r--r-- |
216
38718062709a
updated C2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
211
diff
changeset
|
1 |
int i; |
38718062709a
updated C2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
211
diff
changeset
|
2 |
char ch; |
38718062709a
updated C2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
211
diff
changeset
|
3 |
|
105
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
void get_line(char *dst) { |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
char buffer[8]; |
216
38718062709a
updated C2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
211
diff
changeset
|
6 |
i = 0; |
105
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
7 |
while ((ch = getchar()) != '\n') { |
211
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
8 |
buffer[i++] = ch; |
105
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
} |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
buffer[i] = '\0'; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
strcpy(dst, buffer); |
211
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
12 |
} |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
13 |
|
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
14 |
int match(char *s1, char *s2) { |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
15 |
while(*s1 != '\0' && *s2 != '\0' && *s1 == *s2){ |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
16 |
s1++; s2++; |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
17 |
} |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
18 |
return( *s1 - *s2 ); |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
19 |
} |