码迷,mamicode.com
首页 > 其他好文 > 详细

C和指针 (pointers on C)——第六章:指针(下)习题

时间:2014-07-14 18:16:35      阅读:289      评论:0      收藏:0      [点我收藏+]

标签:c   指针   

有一定的难度,作者只做了前三题!

题目请见 http://download.csdn.net/download/wangpegasus/5701765

1、

char *find_char(char const *source, char const *chars)
{
	char *ptr;
	if(source != NULL && chars != NULL)
	{
		for (; *source != '\0'; source++)
		{
			for (ptr = (char *) chars; *ptr != '\0'; ptr++)
			{
				if (*ptr = * source)
				{
					return (char *)source;
				}
			}
		}
	}
	return NULL;
}
2、

char *match(char *string, char *sub)
{
	while (*sub != '\0')
	{
		string++;
		sub++;
		if (*string != *sub)
		{
			return NULL;
		}
	}
	return string;
}
int del_substr( char * str, char const  *substr)
{
	char * ptr;
	ptr = NULL;
	if ( str == NULL && substr == NULL)
	{
		return 0;
	}
	for (; *str != '\0'; str++)
	{
		ptr = match(str, (char *)substr);
		if (ptr != NULL)
		{
			break;
		}
	}
	while (*str++ = *ptr++)
	{
		;
	}
	return 1;
}
3、

void reverse_string(char *string)
{
	char temp;
	char * last;
	last = string;
	if (string != NULL)
	{
		while (*last != '\0')
		{
			last++;
		}
		last--;
		while (string > last)
		{
			temp = *last;
			*last = *string;
			*string = temp;
			string--;
			last++;
		}
	}
}



C和指针 (pointers on C)——第六章:指针(下)习题,布布扣,bubuko.com

C和指针 (pointers on C)——第六章:指针(下)习题

标签:c   指针   

原文地址:http://blog.csdn.net/liyakun1990/article/details/37765513

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!