-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f90018
commit f08d9e7
Showing
6 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
BINARY=strend | ||
|
||
include ../../Makefile.exerc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# include <stdio.h> | ||
# include "strend.h" | ||
|
||
|
||
void test (char *s, char *t) | ||
{ | ||
printf("strend(\"%s\", \"%s\") => %d\n", s, t, strend(s, t)); | ||
} | ||
|
||
|
||
int main () | ||
{ | ||
char s[] = "Write the function"; | ||
|
||
test(s, ""); | ||
test(s, "n"); | ||
test(s, "x"); | ||
test(s, "nn"); | ||
test(s, "ion"); | ||
test(s, "enction"); | ||
test(s, "Write"); | ||
test(s, "1. Write the function"); | ||
test(s, " Write the function"); | ||
test(s, "Write the function"); | ||
test(s, "function"); | ||
test(s, " function"); | ||
test(s, "ite the function"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
/* | ||
strend: | ||
returns 1 if the string t occurs at the end of the string s, | ||
and zero otherwise | ||
*/ | ||
int strend (char *s, char *t) | ||
{ | ||
char *ts = s, *tt = t; | ||
while (*ts++ != '\0') | ||
; | ||
ts--; | ||
while (*tt++ != '\0') | ||
; | ||
tt--; | ||
while (s <= ts && t <= tt && *ts == *tt) { | ||
ts--; | ||
tt--; | ||
} | ||
return tt < t; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ifndef STREND_H | ||
# define STREND_H | ||
|
||
/* | ||
strend: | ||
returns 1 if the string t occurs at the end of the string s, | ||
and zero otherwise | ||
*/ | ||
int strend (char *s, char *t); | ||
|
||
# endif |
Empty file.
13 changes: 13 additions & 0 deletions
13
chapter_5.pointers_arrays/5_04.strend/tests/0_write_the_function.tout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
strend("Write the function", "") => 1 | ||
strend("Write the function", "n") => 1 | ||
strend("Write the function", "x") => 0 | ||
strend("Write the function", "nn") => 0 | ||
strend("Write the function", "ion") => 1 | ||
strend("Write the function", "enction") => 0 | ||
strend("Write the function", "Write") => 0 | ||
strend("Write the function", "1. Write the function") => 0 | ||
strend("Write the function", " Write the function") => 0 | ||
strend("Write the function", "Write the function") => 1 | ||
strend("Write the function", "function") => 1 | ||
strend("Write the function", " function") => 1 | ||
strend("Write the function", "ite the function") => 1 |