Functions | |
size_t | mystrlen (const char *s) |
int | mystrcmp (const char *s1, const char *s2) |
int | mystrncmp (const char *s1, const char *s2, int n) |
char * | mystrchr (char *haystack, const char needle) |
char * | mystrstr (char *haystack, const char *needle) |
This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
The mystring.h
library serves as a fairly pointless replacement for the perfectly good (better, even) string.h
.
char* mystrchr | ( | char * | haystack, |
const char | needle | ||
) |
A function to find if a character exists in a string.
Goes through the string haystack
looking for the character needle
.
haystack | the string to search |
needle | the character to search for |
haystack
if successful, 0 if not int mystrcmp | ( | const char * | s1, |
const char * | s2 | ||
) |
A function to compare two strings.
Compares two strings, returning -1 if s1
< s2
, 1 if s1
> s2
and 0 if s1
== s2
.
s1 | the string to compare |
s2 | the string to compare s1 to |
s1
< s2
; 1 if s1
> s2
; 0 if s1
== s2
size_t mystrlen | ( | const char * | s | ) |
A function to measure the length of a valid C string.
Goes through the null-terminated (i.e. valid C) string s
character-by-character, returning the length of the string (sans the null terminator).
s | the string to measure |
unsigned int
(size_t
because apparently that's the done thing as of C99, which I'm using because I love for loop initial declarations to bits) int mystrncmp | ( | const char * | s1, |
const char * | s2, | ||
int | n | ||
) |
A function to compare two strings up to a certain point.
Goes through n
characters of s1
, comparing them to the matching characters of s2
. If the characters are different, it returns -1 if s1
< s2
and 1 if s1
> s2
.
If they're the same, it returns 0 if s1
is the same length as s2
(i.e. the same characters are both NUL
). If the function reaches the n
th character of s1
and it remains the same as s2
, it returns 0 also.
s1 | the string to compare |
s2 | the string to compare s1 to |
n | the length of s1 to compare |
char* mystrstr | ( | char * | haystack, |
const char * | needle | ||
) |
A function to find if a string exists as a subset or totality of another.
Goes through the string haystack
looking for the string needle
by executing mystrchr
on each character in turn.
haystack | the string to search |
needle | the (sub)string to search for |
haystack
if successful, 0 if not