void strcpy(dest, src) /*copy src to dest*/ char *dest; const char *src; { while((*dest++ = *src++) != '\0') ; } /*MORE CONCISE AND EQUALLY CORRECT, BUT A LITTLE MISLEADING:*/ void strcpy(dest, src) /*copy src to dest*/ char *dest; const char *src; { while(*dest++ = *src++) ; } void strcat(left, right) /*append the string right to the string left*/ char *left; const char *right; { while(*left != '\0') left++; /*why will this not work if the increment happens in the guard?*/ while((*left++ = *right++) != '\0') ; } int strcmp(s, t) /*return <0 if s0 if s>t*/ const char *s, *t; { while((*s == *t) && (*s != '\0')) s++, t++; return(*s - *t); } int strlen(s) /*length of the string s*/ const char *s; { register int i=0; while(s[i] != '\0') i++; return(i); } /*UNDER WHAT CIRCUMSTANCES WILL THIS PROGRAM NOT WORK?*/ int main() { char fortune[500]; printf("Type your fortune: "); /*print a fortune with "in bed" added*/ scanf("%s", fortune); strcat(fortune, " in bed"); printf("It reads better like this:\n"); printf(fortune); printf("\n"); return 0; } /*HERE'S ONE FIX, BUT UNDER WHAT CIRCUMSTANCES WILL IT STILL NOT WORK?*/ int main() { char fortune[500]; printf("Type your fortune: "); scanf("%s", fortune); strcat(fortune, " in bed"); printf("It reads better like this:\n"); printf("%s\n", fortune); return 0; }