progs/C2a.c
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--
added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
105
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
// Since gets() is insecure and produces lots of warnings, 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
// I use my own input function instead.
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
char ch;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
int i;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
void get_line(char *dst) {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
  char buffer[8];
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
  i = 0;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
  while ((ch = getchar()) != '\n') {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
    buffer[i++] = ch; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
  }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  buffer[i] = '\0';
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
  strcpy(dst, buffer);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
}