Share
Tie strings – algorithm

Tie strings – algorithm

Check equality of two strings

#include <stdio.h>
#include <string.h>

#define TRUE 1
#define FALSE 0
#define MAX 100

int egal(char* s1,char* s2)
{
	if(strlen(s1) != strlen(s2))
	{
		return FALSE;  //daca lungimile celor 2 siruri sunt diferite ele nu sunt egale
	}
	else
		if(s1[0] == s2[0]) //daca primele litere din fiecare sir sunt egale
			if(strlen(s1) == 1) //daca sirul s1 este format dintr-un caracter
				return TRUE;
			else           //altfel elimina litera din fiecare sir si mergi mai departe
				return egal(s1 + 1,s2 + 1);
		else
			return FALSE;
}

void main()
{
	char sir1[MAX],sir2[MAX];
	printf("Sir1 = ");gets(sir1);//scanf("%s",&sir1);
	printf("Sir2 = ");gets(sir2);//scanf("%s",&sir2);
	printf("Sir1 == Sir2 %d\n",egal(sir1,sir2));
}

142,460 total views, 280 views today