1. 程式人生 > >編寫一個函式 接受兩個字串引數 如果 第一個引數被第二個包含 則輸出第一個引數的首字元(圖)

編寫一個函式 接受兩個字串引數 如果 第一個引數被第二個包含 則輸出第一個引數的首字元(圖)


#include "stdAfx.h"
#include "ctype.h"
#include "stdlib.h"
#include "string.h"

int main()
{
	int z;
	int ret(char a[],char b[]);
	char num1[41]="woshiyigedashabi";
	char num2[41]="shi";

	z=ret(num2,num1);

	if(z!=0)
		printf("%c\n",num2[0]);
	else
		return NULL;

	system("pause");
	return 0;
}

int ret(char a[],char b[])
{
	int i=0,j,z=0,q;

	while(b[i]!='\0')
	{
		if(a[0]==b[i])
		{
			for(j=i;j<strlen(a);j++)
			{
				if(a[z]!=b[j])
				{
					q=0;
					break;
				}
				else
					q=1;
					z++;
			}
			if(q==0)
				return 0;
			else
				return 1;
		}
		i++;
	}
}