Exercise 4-1

xiaoxiao2021-03-06  50

#include / * STRRINDEX This function returns the position of the string T on the rightmost appearance. If there is no T in S, return -1. * / int comp_s (const char * s, const char * T) {/ * Returns 1 if S contains T, otherwise returns 0 * / for (; * t! = '/ 0'; t ) {if (* t! = * (S )) Return 0;} Return 1 } Int STRINDEX (const char * s, const char * t) {const char * s_iter = s, * t_iter = T; int index = -1; while (* s_iter! = '/ 0') s_iter , index ; s_iter -;

While (S_ITER--! = s) {index--; if (* s_iter == * t) f (COMP_S (S_ITER, T)) Return Index;} return -1; / * s does not include T * /

} int main () {char * a = "asdkfjwieofjwieojfwjfe"; char * b = "i"; printf ("% d / n", strrIndex (a, b)); return 0;}

转载请注明原文地址:https://www.9cbs.com/read-116167.html

New Post(0)