-
Notifications
You must be signed in to change notification settings - Fork 67
/
ex_5-4.c
51 lines (41 loc) · 840 Bytes
/
ex_5-4.c
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
/* strcmp - compare strings */
/* return <0 is s < t; 0 if s==t; >0 if s>t */
int strcmp(char *s, char *t)
{
int i;
for(i = 0; s[i] == t[i]; i++)
;
return i; // might need to change
}
/* strlen - return length of string */
int strlen_new(char *s)
{
int n;
for(n =0; s[n] != '\0'; n++);
return n;
}
/* strend - compares end of string s with string t */
/* return 1 if string t occurs and 0 otherwise */
int strend(char *s, char *t)
{
int ls, lt;
ls = strlen_new(s); // find length of s
lt = strlen_new(t); // find length of t
// start with end of s and move back comparing with end of t
while(lt >= 0)
{
if(s[ls] != t[lt]) { return 0; }
--ls;
--lt;
}
return 1;
}
int main()
{
char s[] = { "1234567890" };
char t[] = { "67890" };
int ans = strend(s,t);
printf("%d\n", ans);
return 1;
}