Browse Source

Fixed strcpy, added strrem

Stephen Downward 9 months ago
parent
commit
dc139424f6
2 changed files with 17 additions and 7 deletions
  1. 16 7
      libc/string.c
  2. 1 0
      libc/string.h

+ 16 - 7
libc/string.c

@ -91,17 +91,26 @@ void tolowercase(char *in) {
91 91
92 92
void strcpy(char *dest, const char *src)
93 93
{
94
	int dlen = strlen(dest);
95 94
	int slen = strlen(src);
96
97
	//Blank string
98
	for(int i = slen; i < dlen; i++)
99
	{
100
		dest[i] = '\0';
101
	}
102 95
	
103 96
	for(int i = 0; i < slen; i++)
104 97
	{
105 98
		dest[i] = src[i];
106 99
	}
100
	dest[slen] = 0;
101
}
102
103
//Removes all occurances in the string
104
void strrem(char *dest, const char c)
105
{
106
	int dlen = strlen(dest);
107
	for(int i = 0; i < dlen; i++)
108
	{
109
		if(dest[i] == c)
110
		{
111
			dlen--;
112
			strcpy(dest + i, dest + i + 1);
113
			i--;
114
		}
115
	}
107 116
}

+ 1 - 0
libc/string.h

@ -11,5 +11,6 @@ int strcmp(char s1[], char s2[]);
11 11
void strsplit(char *orig, char separator, char *a, char *b);
12 12
void tolowercase(char *in);
13 13
void strcpy(char *dest, const char *src);
14
void strrem(char *dest, const char c);
14 15
15 16
#endif