SCC.150 Assembler Emulator
A compiler for a simple assembler language
 All Files Functions
Functions
mystring.h File Reference
#include <stddef.h>

Go to the source code of this file.

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)
 

Detailed Description

Author
Ben Goldsworthy (rumps) bgold.nosp@m.swor.nosp@m.thy96.nosp@m.@gma.nosp@m.il.co.nosp@m.m
Version
1.0

LICENSE

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/.

DESCRIPTION

Header file for mystring.c.

Function Documentation

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.

Parameters
haystackthe string to search
needlethe character to search for
Returns
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.

Parameters
s1the string to compare
s2the string to compare s1 to
Returns
-1 if the 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).

Parameters
sthe string to measure
Returns
the length of the string as an 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 nth character of s1 and it remains the same as s2, it returns 0 also.

Parameters
s1the string to compare
s2the string to compare s1 to
nthe length of s1 to compare
Returns
-1/1 if the strings don't match, 0 if they do
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.

Parameters
haystackthe string to search
needlethe (sub)string to search for
Returns
haystack if successful, 0 if not