K&R C 第五章练习(实现strcpt,strcmp,strcat等库函数)

void Strcpy(char *des,char *src)
{
	while ( (*des++ = *src++) )
		;
}
int Strcmp(char *des,char *src)
{
	for ( ;*des==*src ;des++,src++ )
		if ( *des==NUL ) {
			return 0;
		}
	return *des-*src;
}
void mstrcat(char *des,char *src)
{
	while ( *des)
		des++;
	while (( *des++ = *src++) )
		;	
}
int Getline(char line[],int maxline)
{
	int c;
	int n;
	for ( n=0;n<maxline&&(c=getchar())!='\n'&&c!=EOF ;n++ )
		line[n]=c;
	line[n]=NUL;
	return n;
}
int mstrend(char *des,char *src)
{
	unsigned len_des,len_src;
	int flag;
	len_des=strlen(des);
	len_src=strlen(src);
	if ( len_des<len_src )
		return 0;
	flag=len_des-len_src;
	des+=flag;
	return strcmp(des,src)?0:1;
}
void mstrncpy(char *des,const char *src,size_t n)
{
	int i=0;
	while (( *des++=*src++)&&++i<n )
		;
}
void mstrncat(char *des,const char *src,size_t n)
{
	while(*des)
		des++;
	size_t i=0;
	while ( (*des++ = *src++)&&++i<n )
		;
}
int strncmp(const char *des,const char *src,size_t n)
{
	while ( *des++ == *src++&&n-- ) {
		if ( *des==NUL||!n )
			return 0;
	}
	return 1;
}

你可能感兴趣的:(K&R C 第五章练习(实现strcpt,strcmp,strcat等库函数))