strlib.c

来自「ADS下的bios工程」· C语言 代码 · 共 104 行

C
104
字号
#include <bios/stdio.h>#include <bios/string.h>u32 str_ncmp(char* str1 , char* str2 , u32 n){        u32 i = 0;        while(i < n) {                if(str1[i] != str2[i]) return  1;                i++;        }        return  0;}u32 strtoint(char *str, u32 count){        u32 temp = 0;        u32 total = 0 ;        while(count)        {                temp = *str++ - '0';                total += temp * power(10,count-1);                count--;        }        return total;}u32 hexstrtohex(char *str, u32 count){        u32 temp = 0;        u32 total = 0 ;        while(count)        {                count--;                if(('0'<=(*str))&&((*str) <= '9'))                {                        temp = *str - '0';                    total += temp << (4*count);                    temp = 0;                }                else if(('a'<=(*str))&&((*str) <= 'f'))                {                        switch(*str)                        {                                case 'a': temp = 10; break;                                case 'b': temp = 11; break;                                case 'c': temp = 12; break;                                case 'd': temp = 13; break;                                case 'e': temp = 14; break;                                case 'f': temp = 15; break;                                default: break;                        }                        total +=temp << (4*count);                        temp = 0;                }                str++;        }        return total;}u32 strlen(char *s){        return strnlen(s, MAX_LINE_SIZE);}int power(u32 value, u32 n){        int       count;        u32       result = 1; /* value returned */                 if (n < 0)             return -1;        for(count = 0; count < n; count++)               result =  result * value;         return result;}char * strcat(char * dest, char * src){	char *tmp = dest;	while (*dest)		dest++;	while ((*dest++ = *src++) != '\0') ;	return tmp;}char * strchr(char *s, int c){     register char ch;     for(;;)     {	 if((ch= *s) == c) return s;	 if(ch == '\0') return 0;	 s++;     }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?