[ create a new paste ] login | about

Link: http://codepad.org/ZYsTVyTB    [ raw code | output | fork ]

C, pasted on Nov 24:
#include<stdio.h>
#include<conio.h>
#include<string.h>

int STRLEN(char s[])
{
	int count = 0;
	while (s[count] != '\0')
	{
		count++;
	}
	return count;
}

int STRCMP(char s1[], char s2[])
{
	int length1 = STRLEN(s1);
	int length2 = STRLEN(s2);

	int lengthMin = (length1 < length2) ? length1 : length2;
	for(int i = 0; i < lengthMin; i++)
	{
		if(s1[i] < s2[i])
		{
			return -1;
		}
		else if(s1[i] > s2[i])
		{
			return 1;
		}
	}
	if (length1 > length2)
	{
		return 1;
	}
	else if (length1 < length2)
	{
		return -1;
	}
	return 0;
}

int main()
{
	char s1[] = "abc";
	char s2[] = "abcd";

	int kq = STRCMP(s1,s2);
	printf("\nKq = %d",kq);

	getch();
	return 0;
}


Output:
1
2
3
Line 17: error: conio.h: No such file or directory
In function 'STRCMP':
Line 21: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: