C examples for String:String Function
Create function to check is a string is ending with another string
#include <stdio.h> #define MAXLINE 1000//w ww .ja va 2s . c o m int strend(char *s, char *t); int main(void) { char *s = "this is a test", *t = "test"; printf("string t is%s at the end of the string s.\n", strend(s, t) ? "" : " not"); return 0; } int strend(char *s, char *t) { int sl, tl; sl = tl = 0; while (*s++) sl++; while (*t++) tl++; if (sl >= tl) { s -= tl; t -= tl; while (*s++ == *t++){ if (!*s) return 1; } } return 0; }