blob: 66c8f6e15564285a18b0ff86c017b615ae6d3e99 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#include <stdio.h>
#define MAXLEN 1000
/* finds the rightmost occurrence of t in s */
int strindex(char s[], char t);
int main(int argc, char *argv[]) {
int i, c, t;
char s[MAXLEN];
printf("source: ");
for (i = 0; i < MAXLEN - 1 && (c = getchar()) != '\n' && c != EOF; i++)
s[i] = c;
s[i] = 0;
printf("character: ");
t = getchar();
printf("index: %d\n", strindex(s, t));
return 0;
}
int strindex(char s[], char t) {
int i, index;
index = -1;
for (i = 0; s[i] != 0; i++) {
if (s[i] == t)
index = i;
}
return index;
}
|