首页 > 代码库 > 常见函数实现

常见函数实现

---恢复内容开始---

strcpy实现:

char *mycopy(char *strDest,const char *strSrc){		if (strDest == NULL || strSrc =http://www.mamicode.com/= NULL )>

  bigint:

 

# include<stdio.h># include<string.h># include<stdlib.h>void multiply(const char* a,const char* b,char* c){	int i,j,ca,cb,* s;	ca=strlen(a);	cb=strlen(b);	s=(int*)malloc(sizeof(int)*(ca+cb));	for (i=0;i<ca+cb;i++)		s[i]=0;	for (i=0;i<ca;i++)		for (j=0;j<cb;j++)			s[i+j+1]+=(a[i]-‘0‘)*(b[j]-‘0‘);     //s[0]保留为最后的进位	for (i=ca+cb-1;i>=0;i--)		if (s[i]>=10)                               		{			s[i-1]+=s[i]/10;                        			s[i]%=10;		}		i=0;		while (s[i]==0)			i++;		for (j=0;i<ca+cb;i++,j++)			c[j]=s[i]+‘0‘;		c[j]=‘\0‘;		free(s);}int main(void){	char a[]="123511156112122132312235465611";	char b[]="4561561233211213213213213131232665";	char *c=(char *)malloc(strlen(a)+strlen(b)+1);	multiply(a,b,c);	printf("%s",c);	free(c);	getchar();	return 0;}

  参考链接:http://hi.baidu.com/ok558/item/9c5d78e22cd798a9c00d7534

 strstr

char * __cdecl Mystrstr (	const char * str1,	const char * str2	){	char *cp = (char *) str1;	char *s1, *s2;	if ( !*str2 )		return((char *)str1);	while (*cp)	{		s1 = cp;		s2 = (char *) str2;		while ( *s1 && *s2 && !(*s1-*s2) )			s1++, s2++;		if (!*s2)			return(cp);		cp++;	}	return(NULL);}