progs/C2a.c
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Mon, 06 Oct 2014 21:23:31 +0100
changeset 213 9c2fa54c7c2d
parent 211 e6e160c7ea33
child 216 38718062709a
permissions -rw-r--r--
updated
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
void get_line(char *dst) {
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
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
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
  }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     8
  buffer[i] = '\0';
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
}