Added updated x_string
This commit is contained in:
parent
7d326f6057
commit
22eadc8ad7
@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// return the length of string to the null terminator
|
||||||
int x_strlen(char* str){
|
int x_strlen(char* str){
|
||||||
char* ptr = str;
|
char* ptr = str;
|
||||||
while(*ptr != '\0'){
|
while(*ptr != '\0'){
|
||||||
@ -9,6 +10,8 @@ int x_strlen(char* str){
|
|||||||
return ptr - str;
|
return ptr - str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// copy one string to another destination
|
||||||
|
// must include the size of the destination
|
||||||
void x_strcpy(char* dest, char* src, const int size_dest){
|
void x_strcpy(char* dest, char* src, const int size_dest){
|
||||||
char* dest_ptr = dest;
|
char* dest_ptr = dest;
|
||||||
char* src_ptr = src;
|
char* src_ptr = src;
|
||||||
@ -26,7 +29,32 @@ void x_strcpy(char* dest, char* src, const int size_dest){
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// compare two strings
|
||||||
|
// return 0 if equal to eachother
|
||||||
|
// return -1 if not
|
||||||
|
int x_strcmp (char* str1, char* str2){
|
||||||
|
char* ptr1 = str1;
|
||||||
|
char* ptr2 = str2;
|
||||||
|
|
||||||
|
while(*ptr1 != '\0' && *ptr2 != '\0'){
|
||||||
|
if(*ptr1 != *ptr2){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr1++;
|
||||||
|
ptr2++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if havent reached the end of one of the strings
|
||||||
|
if (*ptr1 != '\0' || *ptr2 != '\0'){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// concatinate two strings
|
||||||
char* x_strconcat(char* str1, char* str2){
|
char* x_strconcat(char* str1, char* str2){
|
||||||
|
|
||||||
char* new_string;
|
char* new_string;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
int x_strlen(char*);
|
int x_strlen(char*);
|
||||||
void x_strcpy(char*, char*, const int);
|
void x_strcpy(char*, char*, const int);
|
||||||
|
int x_strcmp(char*, char*);
|
||||||
char* x_strconcat(char*, char*);
|
char* x_strconcat(char*, char*);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user