author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Mon, 06 Oct 2014 20:52:53 +0100 | |
changeset 211 | e6e160c7ea33 |
parent 115 | c4008b31df8e |
child 216 | 38718062709a |
permissions | -rw-r--r-- |
105
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1 |
void get_line(char *dst) { |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
char buffer[8]; |
211
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
3 |
int i = 0; |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
4 |
char ch; |
105
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
while ((ch = getchar()) != '\n') { |
211
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
6 |
buffer[i++] = ch; |
105
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 |
buffer[i] = '\0'; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
strcpy(dst, buffer); |
211
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
10 |
} |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
11 |
|
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
12 |
int match(char *s1, char *s2) { |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
13 |
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
|
14 |
s1++; s2++; |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
15 |
} |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
16 |
return( *s1 - *s2 ); |
e6e160c7ea33
added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
115
diff
changeset
|
17 |
} |