D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] word similarities



Neil Williams wrote:

Must be in C, not C++

Basically, with two strings, a calculation for the distance between the two strings so can determine the closest match.


Sorry, I've been using C++ for so long. Wouldn't the strcmp function do the job? Something like this?


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

char str1[3] = "B0";
char str2[3] = "A9";
char str3[3] = "B1";
char str4[4] = "B0";

int result;

void main()
{

result = strcmp(str1,str2);
if (result == 0)
printf("strings are identical\n");
else if(result < 0)
printf("string1 is less than string 2\n");
else
printf("string1 is greater than string 2\n");

result = strcmp(str2,str1);
if (result == 0)
printf("strings are identical\n");
else if(result < 0)
printf("string1 is less than string 2\n");
else
printf("string1 is greater than string 2\n");

result = strcmp(str1,str4);
if (result == 0)
printf("strings are identical\n");
else if(result < 0)
printf("string1 is less than string 2\n");
else
printf("string1 is greater than string 2\n");
}

Carl

--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.



Lynx friendly