paleofetch

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit eac72c538a9911ca26d460e690a38ff3a3e43b76
parent b6b10a07378ceebd496a60063ded16001d2aa363
Author: sam-barr <samfbarr@outlook.com>
Date:   Thu, 23 Apr 2020 14:08:39 -0500

Use the pointer returned by strstr rather than calculating the offset

Diffstat:
Mpaleofetch.c | 11++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/paleofetch.c b/paleofetch.c @@ -68,15 +68,12 @@ void truncate_spaces(char *str) { */ void remove_substring(char *str, const char* substring, size_t len) { /* shift over the rest of the string to remove substring */ - int offset = strstr(str, substring) - str; - if(offset < 0) return; + char *sub = strstr(str, substring); + if(sub == NULL) return; int i = 0; - for(;;) { - if(*(str+offset+i) == '\0') break; - *(str+offset+i) = *(str+offset+i+len); - i++; - } + do *(sub+i) = *(sub+i+len); + while(*(sub+(++i)) != '\0'); } char *get_title() {