/******************************************************************************
File Name :
Version :
Author :
Created : 2014/01/16
Last Modified :
Description :
Function List :
History :
1.Date : 2014/01/16
Author :
Modification: Created file
******************************************************************************/
#include <stdlib.h>
unsigned int strlenth(char *s) /* 获取字符串长度 */
{
/* 代码在这里实现 */
unsigned int lenth = 0;
if (NULL == s && NULL == *s)
{
return 0;
}
while(*s != '\0')
{
lenth++;
s++;
}
return lenth;
}
void strcopy(char **target, char *source) /* 字符串拷贝 */
{
/* 代码在这里实现 */
int iStrLen = 0;
int iLoop = 0;
char * szTemp = NULL;
if (NULL == source && NULL == *source)
{
return ;
}
iStrLen = strlenth(source);
szTemp = (char *)malloc(iStrLen + 1);
if (NULL == szTemp)
{
return;
}
for(iLoop = 0; iLoop < iStrLen; iLoop++)
{
szTemp[iLoop] = source[iLoop];
}
szTemp[iStrLen] = '\0';
*target = szTemp;
return;
}
int strcompare(char *s, char *t) /* 字符串比较,s>t,则返回1;s=t,则返回0;s<t,则返回-1 */
{
/* 代码在这里实现 */
int iResult = 0;
int iSrcStrLen = 0;
int iTagSrcLen = 0;
int iLoop = 0;
iSrcStrLen = strlenth(s);
iTagSrcLen = strlenth(t);
if ( iSrcStrLen > iTagSrcLen)
{
while(iTagSrcLen--)
{
if ((int)s[iLoop] > (int)t[iLoop])
{
return 1;
}
else
{
if ((int)s[iLoop] < (int)t[iLoop])
{
return -1;
}
continue;
}
iLoop++;
}
if (iSrcStrLen > iTagSrcLen)
{
return 1;
}
else
return -1;
}
else
{
if (iSrcStrLen < iTagSrcLen)
{
while(iSrcStrLen--)
{
if ((int)s[iLoop] > (int)t[iLoop])
{
return 1;
}
else
{
if ((int)s[iLoop] < (int)t[iLoop])
{
return -1;
}
continue;
}
iLoop++;
}
if (iSrcStrLen > iTagSrcLen)
{
return 1;
}
else
return -1;
}
else
{
while(iSrcStrLen--)
{
if ((int)s[iLoop] > (int)t[iLoop])
{
return 1;
}
else
{
if ((int)s[iLoop] < (int)t[iLoop])
{
return -1;
}
continue;
}
iLoop++;
}
}
}
return 0;
}
void strcombine(char **x, char *s, char *t) /* 字符串连接,将字符串t接到s后面,x为连接后的新串 */
{
/* 代码在这里实现 */
int iSrcStrLen = 0;
int iTagStrLen = 0;
int iLoop = 0;
char *pTemp = NULL;
iSrcStrLen = strlenth(s);
iTagStrLen = strlenth(t);
pTemp = (char *)malloc(iSrcStrLen + iTagStrLen + 1);
if (NULL == pTemp)
{
return ;
}
for (iLoop; iLoop < iSrcStrLen; iLoop++)
{
pTemp[iLoop] = s[iLoop];
}
for (iLoop = 0; iLoop < iTagStrLen; iLoop++)
{
pTemp[iSrcStrLen + iLoop] = t[iLoop];
}
pTemp[iSrcStrLen + iTagStrLen] = '\0';
*x = pTemp;
return ;
}
void strcatch(char *s, unsigned int index, unsigned int lenth, char **t) /* 字符串截取,从第index个字符开始,截取lenth长度的字符串,并输出到字符串t */
{
/* 代码在这里实现 */
int iLoop = 0;
unsigned int iSrcStrLen = 0;
char *pTemp = NULL;
iSrcStrLen = strlenth(s);
if ((lenth > iSrcStrLen) || (lenth == 0) || ((index + lenth) > iSrcStrLen))
{
return ;
}
pTemp = (char *)malloc(iSrcStrLen + 1);
if (NULL == pTemp)
{
return ;
}
while( lenth--)
{
pTemp[iLoop] = s[index];
iLoop++;
index++;
}
pTemp[iLoop] = '\0';
*t = pTemp;
return ;
}
bool strsubstr(char *s, char *sub) /* 字符串子串查找,如果子串sub在s中存在,则返回1,否则返回0 */
{
/* 代码在这里实现 */
bool result = 0;
int iSrcStrLen = 0;
int iSubStrLen = 0;
int iLoop = 0;
int jLoop = 0;
iSrcStrLen = strlenth(s);
iSubStrLen = strlenth(sub);
for (iLoop; iLoop < iSubStrLen; iLoop++)
{
for (jLoop; jLoop < iSrcStrLen; jLoop++)
{
if (sub[iLoop] == s[jLoop])
{
iLoop++;
if ('\0' == sub[iLoop])
{
result = 1;
break;
}
continue;
}
}
iLoop++;
}
return result;
}
File Name :
Version :
Author :
Created : 2014/01/16
Last Modified :
Description :
Function List :
History :
1.Date : 2014/01/16
Author :
Modification: Created file
******************************************************************************/
#include <stdlib.h>
unsigned int strlenth(char *s) /* 获取字符串长度 */
{
/* 代码在这里实现 */
unsigned int lenth = 0;
if (NULL == s && NULL == *s)
{
return 0;
}
while(*s != '\0')
{
lenth++;
s++;
}
return lenth;
}
void strcopy(char **target, char *source) /* 字符串拷贝 */
{
/* 代码在这里实现 */
int iStrLen = 0;
int iLoop = 0;
char * szTemp = NULL;
if (NULL == source && NULL == *source)
{
return ;
}
iStrLen = strlenth(source);
szTemp = (char *)malloc(iStrLen + 1);
if (NULL == szTemp)
{
return;
}
for(iLoop = 0; iLoop < iStrLen; iLoop++)
{
szTemp[iLoop] = source[iLoop];
}
szTemp[iStrLen] = '\0';
*target = szTemp;
return;
}
int strcompare(char *s, char *t) /* 字符串比较,s>t,则返回1;s=t,则返回0;s<t,则返回-1 */
{
/* 代码在这里实现 */
int iResult = 0;
int iSrcStrLen = 0;
int iTagSrcLen = 0;
int iLoop = 0;
iSrcStrLen = strlenth(s);
iTagSrcLen = strlenth(t);
if ( iSrcStrLen > iTagSrcLen)
{
while(iTagSrcLen--)
{
if ((int)s[iLoop] > (int)t[iLoop])
{
return 1;
}
else
{
if ((int)s[iLoop] < (int)t[iLoop])
{
return -1;
}
continue;
}
iLoop++;
}
if (iSrcStrLen > iTagSrcLen)
{
return 1;
}
else
return -1;
}
else
{
if (iSrcStrLen < iTagSrcLen)
{
while(iSrcStrLen--)
{
if ((int)s[iLoop] > (int)t[iLoop])
{
return 1;
}
else
{
if ((int)s[iLoop] < (int)t[iLoop])
{
return -1;
}
continue;
}
iLoop++;
}
if (iSrcStrLen > iTagSrcLen)
{
return 1;
}
else
return -1;
}
else
{
while(iSrcStrLen--)
{
if ((int)s[iLoop] > (int)t[iLoop])
{
return 1;
}
else
{
if ((int)s[iLoop] < (int)t[iLoop])
{
return -1;
}
continue;
}
iLoop++;
}
}
}
return 0;
}
void strcombine(char **x, char *s, char *t) /* 字符串连接,将字符串t接到s后面,x为连接后的新串 */
{
/* 代码在这里实现 */
int iSrcStrLen = 0;
int iTagStrLen = 0;
int iLoop = 0;
char *pTemp = NULL;
iSrcStrLen = strlenth(s);
iTagStrLen = strlenth(t);
pTemp = (char *)malloc(iSrcStrLen + iTagStrLen + 1);
if (NULL == pTemp)
{
return ;
}
for (iLoop; iLoop < iSrcStrLen; iLoop++)
{
pTemp[iLoop] = s[iLoop];
}
for (iLoop = 0; iLoop < iTagStrLen; iLoop++)
{
pTemp[iSrcStrLen + iLoop] = t[iLoop];
}
pTemp[iSrcStrLen + iTagStrLen] = '\0';
*x = pTemp;
return ;
}
void strcatch(char *s, unsigned int index, unsigned int lenth, char **t) /* 字符串截取,从第index个字符开始,截取lenth长度的字符串,并输出到字符串t */
{
/* 代码在这里实现 */
int iLoop = 0;
unsigned int iSrcStrLen = 0;
char *pTemp = NULL;
iSrcStrLen = strlenth(s);
if ((lenth > iSrcStrLen) || (lenth == 0) || ((index + lenth) > iSrcStrLen))
{
return ;
}
pTemp = (char *)malloc(iSrcStrLen + 1);
if (NULL == pTemp)
{
return ;
}
while( lenth--)
{
pTemp[iLoop] = s[index];
iLoop++;
index++;
}
pTemp[iLoop] = '\0';
*t = pTemp;
return ;
}
bool strsubstr(char *s, char *sub) /* 字符串子串查找,如果子串sub在s中存在,则返回1,否则返回0 */
{
/* 代码在这里实现 */
bool result = 0;
int iSrcStrLen = 0;
int iSubStrLen = 0;
int iLoop = 0;
int jLoop = 0;
iSrcStrLen = strlenth(s);
iSubStrLen = strlenth(sub);
for (iLoop; iLoop < iSubStrLen; iLoop++)
{
for (jLoop; jLoop < iSrcStrLen; jLoop++)
{
if (sub[iLoop] == s[jLoop])
{
iLoop++;
if ('\0' == sub[iLoop])
{
result = 1;
break;
}
continue;
}
}
iLoop++;
}
return result;
}