-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchapt5.c
71 lines (61 loc) · 964 Bytes
/
chapt5.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
void strcat_modif(char *s, char *t);
void strcpy_modif(char *s, char *t);
int strend(char *s, char *t);
int strlen_modif(char *s);
int strcmp_modif(char *s, char *t);
int main(int argc, char *argv[])
{
printf("Exercice 5.3\n");
char s[] = "testadhdhdhhd";
char *t = "hdhhd";
strcat_modif(s,t);
printf("%s\n", s);
printf("%d\n", strend(s, t));
return 0;
}
void strcat_modif(char *s, char *t)
{
while(*s)
{
s++;
}
strcpy_modif(s, t);
}
void strcpy_modif(char *s, char *t)
{
while(*s++ = *t++)
;
printf("%s\n", s );
}
int strend(char *s, char *t)
{
int l1 = strlen_modif(s);
int l2 = strlen_modif(t);
if (l1 > l2)
{
s+= l1 - l2;
return strcmp_modif(s,t);
}
return 0;
}
int strcmp_modif(char *s, char *t)
{
for(; *s == *t; s++, t++)
{
if(*s == '\0') // end of string so SUCCESS
{
return 1;
}
}
return *s - *t;
}
int strlen_modif(char *s)
{
int i;
for(i=0; *s != '\0'; s++)
{
i++;
}
return i;
}