CeDOS - Commit a86abf4e

string.h: Add strchr function Finds the index of a character inside a string
Celina Sophie Kalus
Wed, 06 Dec 2023 00:45:42 +0100
2 files changed, 17 insertions(+), 0 deletions(-)
M common/string.ccommon/string.c

@@ -51,4 +51,20 @@ }

i++; } +} + +const char * strchr ( const char * str, int character ) { + int i = 0; + + while (1) { + if (str[i] == 0) { + return NULL; + } + + if (str[i] == character) { + return &(str[i]); + } + + i++; + } }
M common/string.hcommon/string.h

@@ -35,5 +35,6 @@

unsigned int strlen (const char *str); char *strcpy(char *destination, const char *source); int strcmp(const char *str1, const char *str2); +const char * strchr ( const char * str, int character ); #endif