I've begun to delve the deep wisdom of K&R and resolved to complete each of the exercises presented therein.
Now, I have a working example of exercise 5-4, which asks you to "Write the function strend(s, t), which returns 1 if the string t occurs at the end of the string s, and zero otherwise."
If anyone has any constructive criticism to offer on the composition of my code, it would be much appreciated.
I've included main() for convenience.
Thanks!Code:#include <stdio.h> int strend(char *s, char *t); #define SIZE 16 int main() { char helloWorld[SIZE] = "Hello world!"; char justWorld[SIZE] = "world!"; if (strend(helloWorld, justWorld)) printf("justWorld occurs at the end of helloWorld\n"); else printf("justWorld DOES NOT occur at the end of helloWorld\n"); return 0; } int strend(char *s, char *t) { while (*s++) { if (*t == *s) { while ((*s++ == *t++) && (*t != '\0')) ; if (*s == '\0' && *t == '\0') return 1; return 0; } } return 0; }