progs/C2a.c
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Wed, 11 Jan 2017 12:29:18 +0000
changeset 509 aa2a09b9823c
parent 216 38718062709a
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
216
38718062709a updated C2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
     1
int i;
38718062709a updated C2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
     2
char ch;  
38718062709a updated C2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
     3
105
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
void get_line(char *dst) {
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
  char buffer[8];
216
38718062709a updated C2
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 211
diff changeset
     6
  i = 0;
105
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     7
  while ((ch = getchar()) != '\n') {
211
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
     8
    buffer[i++] = ch;
105
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     9
  }
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    10
  buffer[i] = '\0';
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    11
  strcpy(dst, buffer);
211
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
    12
}
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
    13
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
    14
int match(char *s1, char *s2) {
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
    15
  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
    16
    s1++; s2++;
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
    17
  }
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
    18
  return( *s1 - *s2 );
e6e160c7ea33 added files
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 115
diff changeset
    19
}