diff --git a/x_string/src/x_string.c b/x_string/src/x_string.c index 4c75ae5..20d1674 100644 --- a/x_string/src/x_string.c +++ b/x_string/src/x_string.c @@ -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 diff --git a/x_string/src/x_string.h b/x_string/src/x_string.h index 8ccf9d3..2b6d621 100644 --- a/x_string/src/x_string.h +++ b/x_string/src/x_string.h @@ -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*);