Next: Computing a hash Up: Idiomatic C Previous: Remove trailing spaces

strcat()

void strcat(char s[], char t[])
  {
  int i, j;

  i= j= 0;
  while (s[i] != '\0') i++;                 /* find end of s */
  while ( ( s[i++] = t[j++] ) != '\0')  ;   /* copy it */
  }

Note: the use of the while to find the end of the string.

Note: the idiomatic use of an empty while clause; the work is done within the while control itself.

Note: at-least-two-for-the-price-of-one: the assignment, the != test and the update of i and j. Arguably this is getting too dense to read easily.



Next: Computing a hash Up: Idiomatic C Previous: Remove trailing spaces


maspjw@
Tue Sep 27 15:29:34 BST 1994