常用函数源码

来源:互联网 发布:维普数据库论文查询 编辑:程序博客网 时间:2024/04/26 18:05
char* getData(int iYear, int iMonth, int iDay, int inCountDay)
{
char psResult[100]="";


if ( iYear <= 0 || iMonth <= 0 || iDay <=0 || inCountDay <0 || iMonth >12)
{
return psResult;
}


int iSumday = 0;


int iLeapYear = 0;


int month_Data[12] = {31,28,31,30,31,30,31,31,30,31,30,31};


if(iYear%400==0 || (iYear%4==0 && iYear%100!=0))
{
iLeapYear=1;
}


if (iMonth == 2)
{
if ((month_Data[iMonth-1]+iLeapYear)<iDay || iDay <=0)
{
return psResult;
}
}


iSumday = iDay + inCountDay;


while (iSumday > month_Data[iMonth -1])
{

if (iMonth == 2)
{
if (iLeapYear == 1)
{
month_Data[iMonth -1]+=1;
}
}

iSumday -= month_Data[iMonth - 1];


iMonth ++;


if (iMonth >12)
{
iYear++;
iMonth = 1;
}


if(iYear%400==0 || (iYear%4==0 && iYear%100!=0))
{
iLeapYear=1;
}
else
{
iLeapYear = 0;
}
}


iDay = iSumday;


sprintf(psResult, "%d年%d月%d日", iYear,iMonth,iSumday);


return psResult;
}
char * strstrs(char* lsrc, char* des)
{
char* pszResult = NULL;


if (!*des)
{
return lsrc;
}


while (*lsrc)
{
char* pszTemp = des;
char* pszBuffer = lsrc;


while (*pszBuffer++ == *pszTemp++)
{
if (!*pszTemp)
{
pszResult = lsrc;
}
}


lsrc+=1;
}


return pszResult;


}


size_t my_strlena(char* psz)
{
size_t ileng=0;


if (psz == NULL)
{
return ileng;
}


while(*psz++)
{
ileng ++;
}
return ileng;
}


size_t my_strlen(char* str)
{
assert(str != NULL);


const char* eos = str;


while (*eos++);


return (eos -str - 1);
}


char* my_strcat(char* dest, char* src)
{
char* pszResult = dest;


assert((dest != NULL)&&(src != NULL));


while(*dest)
{
dest++;
}


while (*dest++ = *src++);


return pszResult;
}




char* my_strcpy(char* dest, char* src)
{
char* pszResult = NULL;


if (dest == NULL && src == NULL)
{
return pszResult;
}


pszResult = dest;


while (*dest++ = *src++);


return pszResult;
}


int BigToLittle(int A)
{
return
((((A) & 0x000000ff) << 24) |
(((A) & 0x0000ff00) << 8) |
(((A) & 0x00ff0000) >> 8) |
(((A) & 0xff000000) >> 24));
}






int my_atoi(char* str)
{
int value = 0;
int isigned =0;


if (*str == '-')
{
str++;
isigned = 1;
}

while(*str>='0' && *str<='9')
{
value *= 10;
value += *str - '0';
str++;
}


if (isigned == 1)
{
value = -value;
}

return value;
}
0 0