Fixed bug that missed the null terminator on the dest in x_strcpy
This commit is contained in:
parent
787bf40377
commit
4fb48e6912
@ -12,15 +12,15 @@ int x_strlen(char* 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){
|
||||
// if greater than destination than stop and return 1
|
||||
int x_strcpy(char* dest, char* src, const int size_dest){
|
||||
char* dest_ptr = dest;
|
||||
char* src_ptr = src;
|
||||
int i = 0;
|
||||
|
||||
while(*src_ptr != '\0'){
|
||||
if (i >= size_dest){
|
||||
fprintf(stderr, "Error: x_strcpy\nSource string exeeds destination memory\n");
|
||||
exit(1);
|
||||
return 1;
|
||||
}
|
||||
*dest_ptr = *src_ptr;
|
||||
dest_ptr++;
|
||||
@ -28,6 +28,9 @@ void x_strcpy(char* dest, char* src, const int size_dest){
|
||||
i++;
|
||||
}
|
||||
|
||||
*dest_ptr = *src_ptr;
|
||||
return 0;
|
||||
|
||||
}
|
||||
// compare two strings
|
||||
// return 0 if equal to eachother
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define X_STRING_H
|
||||
|
||||
int x_strlen(char*);
|
||||
void x_strcpy(char*, char*, const int);
|
||||
int x_strcpy(char*, char*, const int);
|
||||
int x_strcmp(const char*, const char*);
|
||||
char* x_strconcat(char*, char*);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user