author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 23 Sep 2014 11:45:21 +0100 | |
changeset 170 | 1c8ad2848d3b |
parent 115 | c4008b31df8e |
child 211 | e6e160c7ea33 |
permissions | -rw-r--r-- |
115
c4008b31df8e
added material
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
105
diff
changeset
|
1 |
// Since gets() is insecure and produces lots |
c4008b31df8e
added material
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
105
diff
changeset
|
2 |
// of warnings, thereofre I use my own input |
c4008b31df8e
added material
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
105
diff
changeset
|
3 |
// function instead. |
105
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
char ch; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
int i; |
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 |
void get_line(char *dst) { |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
char buffer[8]; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
9 |
i = 0; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
10 |
while ((ch = getchar()) != '\n') { |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
buffer[i++] = ch; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
12 |
} |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
13 |
buffer[i] = '\0'; |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
14 |
strcpy(dst, buffer); |
40c51038c9e4
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
15 |
} |