progs/C2a.c
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 09 Oct 2013 15:51:03 +0100
changeset 115 c4008b31df8e
parent 105 40c51038c9e4
child 211 e6e160c7ea33
permissions -rw-r--r--
added material
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
char ch;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
int i;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
void get_line(char *dst) {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
  char buffer[8];
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
  i = 0;
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  while ((ch = getchar()) != '\n') {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
    buffer[i++] = ch; 
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    12
  }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    13
  buffer[i] = '\0';
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    14
  strcpy(dst, buffer);
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    15
}