Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int len(const char str[]) {
- int i = 0;
- while(*str++) i++;
- return i;
- }
- int find_char(const char str[], char c) {
- if(len(str) == 0) return -1;
- int i = 0;
- while(*str) {
- if(*str++ == c)
- return i;
- i++;
- }
- return -1;
- }
- int rfind_char(const char str[], char c) {
- if(len(str) == 0) return -1;
- int i = 0;
- int last = 0;
- while(*str) {
- if(*str++ == c)
- last = i;
- i++;
- }
- return last;
- }
- int main() {
- printf("%d\n%d", find_char("To jest test", 's') , rfind_char("To jest test", 's'));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement