c_programming_language/exercices/functions/ex_4_1.c
2026-02-06 20:23:03 +03:00

20 lines
416 B
C

/*
* Exercise 4-1. Write the function strindex(s,t) which returns the position of
* the rightmost occurrence of t in s, or -1 if there is none
*/
#include <stdio.h>
#include <string.h>
int strindex(char s[], char t) {
for (int i = 0; i < strlen(s); i++) {
if (s[i] == t) {
return i;
}
}
return -1;
}
int main() {
int index = strindex("Hello world", 'w');
printf("Index: %d\n", index);
}