⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.c

📁 一个小型的操作系统,采用gcc进行开发,几千行的代码,方便初学者学习
💻 C
字号:
/**  Snixos Project version 1.0, 2003.6*  (C) Copyright 2003,2004,2005 Jockeyson,KeqiangGao <Snallie@tom.com>*  All Rights Reserved.*  Distributed under the terms of the GNU General Public License.**  This program is a free and open source software and you can redistribute *  it and/or modify it under the terms of the GNU General Public License as*  published by the Free Software Foundation. As no any liability is assumed *  for any incidental or consequential damages in connection with the *  information or program fragments contained herein,so any exception arised*  is at your own risk. It is ABSOLUTELY WITHOUT ANY WARRANTY.*  Bug report please send to Snallie@tom.com .*//*  string.c: function for string manipulation in Snixos Project  Author : Snallie@tom.com  Time   : 2003.6*/#ifndef NULL#define NULL ((void *) 0)#endif/* char * strcpy(char * dest,const char *src)       The  strcpy()  function  copies  the string pointed to be src (including the terminating       `\0' character) to the array pointed to by dest.  The strings may not overlap,  and  the       destination string dest must be large enough to receive the copy.*/char *strcpy(char *dest, const char *src){    char *tmpstr;    tmpstr = dest;    while (*dest++ = *src++);    return tmpstr;}/* char *strncpy(char *dest, const char *src, int n);   copy s2 to s1, truncating or null padding as necessary to create a string   n characters long*/char *strncpy(char *dest, const char *src, int n){    char *tmpstr;    tmpstr = dest;    while (n--) {	if (!(*dest++ = *src++))	    break;    }    while (n-- > 0)	*dest++ = 0;    return tmpstr;}/* char *strcat(char *dest, const char *src);       The  strcat()  function  appends  the src string to the dest string overwriting the `\0'       character at the end of dest, and then adds a terminating `\0' character.   The  strings       may not overlap, and the dest string must have enough space for the result.*/char *strcat(char *dest, const char *src){    char *tmpstr;    tmpstr = dest;    while (*dest)	dest++;    while (*dest++ = *src++);    return tmpstr;}/* char * strncat(char * dest,const char * src,int count)   append src to dest, truncating at n characters if necessary */char *strncat(char *dest, const char *src, int count){    char *tmpstr;    tmpstr = dest;    while (*dest)	dest++;    while (count--) {	if (!(*dest++ = *src++))	    break;    }    return tmpstr;}/*int strcmp(const char *s1, const char *s2);    The  strcmp()  function  compares the two strings s1 and s2.  It returns an integer less    than, equal to, or greater than zero if s1 is found, respectively, to be less  than,  to    match, or be greater than s2.    i.e. compare s1 and s2    result is <, ==, or > 0 as s1 is <, ==, > s2*/inline int strcmp(const char *s1, const char *s2){    while (1) {	if (*s1 > *s2)	    return 1;	if (*s1 < *s2++)	    return -1;	if (!*s1++)	    return 0;    }    return 0;}/* int strncmp(const char *s1, const char *s2, int n);   compare s1 and s2 for length n   result is <, ==, or > 0 as s1 is <, ==, > s2*/int strncmp(const char *s1, const char *s2, int n){    while (n--) {	if (*s1 > *s2)	    return 1;	if (*s1 < *s2++)	    return -1;	if (!*s1++)	    return 0;    }    return 0;}/*strchr(): find c's first occurance in string s*/char *strchr(const char *s, char c){    char *tmp = (char *) s;    while (*tmp != c && *tmp != 0) {	tmp++;    }    if (*tmp == '\0')	return NULL;    if (*tmp == c)	return tmp;}/* int strlen(const char *s);** return length of s*/int strlen(const char *s){    int length;    length = 0;    while (*s++)	length++;    return length;}/* convert string str to lowercase */char *strlwr(char *str){    char *str2;    str2 = str;    while (*str) {	if (isalpha(*str))	    *str = (*str) | 0x20;	str++;    }    return str2;}/* convert string str to uppercase */char *strupr(char *str){    char *str2;    str2 = str;    while (*str) {	if (isalpha(*str))	    *str = (*str) & 0xdf;	str++;    }    return str2;}void *memcpy(void *dest, const void *src, int n){    int i = 0;    while (i < n) {	*((char *) dest + i) = *((char *) src + i);	i++;    }    return dest;}void *memset(void *s, char c, int count){    int i = 0;    while (i < count) {	*((char *) s + i) = c;	i++;    }    return s;}

⌨️ 快捷键说明

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