C language notes of commonly used functions

An array of display elements

/************************************
function:显示数字数组元素
parameter:arr--数组,len--数组大小
return:void
date:2019-12-2
author:残梦
************************************/
void ArrayPrintNumber(int p[], int len)
{
	int i = 0;

	printf("数组的大小为%d	元素值为:", len);
	while (i < len)
	{
		printf("%2d", p[i++]);
	}
	putchar('\n');
}

/************************************
function:显示字符数组元素
parameter:arr--数组,len--数组大小
return:void
date:2019-12-3
author:残梦
************************************/
void ArrayPrintChar(char p[], int len)
{
	int i = 0;

	printf("数组的大小为%d	元素值为:", len);
	while (i < len)
	{
		printf("%c", p[i++]);
	}
	putchar('\n');
}

The inverted array, inclusive exchange element

/************************************
function:将数组反转,首尾元素调换
parameter:arr--数组名,len--数组大小
return:void
date:2019-12-2
author:残梦
************************************/
/************************************
function:将数组反转,首尾元素调换
parameter:arr--数组名,len--数组大小
return:void
date:2019-12-2
author:残梦
************************************/
void ArrayReversal(int *arr,int len)
{
	int temp = 0, i = 0;
	
	printf("\n反转数组\n");
	for (i = 0; i <= len / 2; i++)
	{
		temp = *(arr + i);
		*(arr+i) = *(arr + (len - 1 - i));
		*(arr + (len - 1 - i)) = temp;
	}
}

Counting the number of the target character array

An array of ways:


```c
/***********************************
function:数组方式统计数组中目标字符的数量
parameter:str[]--数组,TargetChar--统计的字符,len--数组大小
return:统计的数量
date:2019-12-2
author:残梦
***********************************/
int StatisticsChar_Array(char str[], char TargetChar, int len)
{
	int i = 0,num = 0;

	while (i < len)
	{
		if (str[i++] == TargetChar)	{num++;}
	}

	return num;
}
指针方式:

```c
/***********************************
function:指针方式统计数组中目标字符的数量
parameter:p--数组头地址,TargetChar--统计的字符,len--数组大小
return:统计的数量
date:2019-12-2
author:残梦
***********************************/
int StatisticsChar_Pointer(char *p, char TargetChar, int len)
{
	int i = 0, num = 0;

	while (i < len)
	{
		if (*(p+i) == TargetChar)	{ num++; }
		i++;
	}

	return num;
}
Published 10 original articles · won praise 1 · views 439

Guess you like

Origin blog.csdn.net/qq_36561846/article/details/103351801