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