Skip to content

Instantly share code, notes, and snippets.

@GingerBear
Created December 8, 2013 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GingerBear/7863876 to your computer and use it in GitHub Desktop.
Save GingerBear/7863876 to your computer and use it in GitHub Desktop.
Dummy matching of type of in string
#include <stdio.h>
int match_type(char *str, char *type)
{
printf("%s\n", str);
printf("%s\n", type);
int i = 0, j = 0, count = 0;
char tmp1[10];
char c;
while ((c = str[i]) != '\0')
{
printf("%c\n", c);
if (c == '|')
{
tmp1[j] = '\0';
return (strcmp(tmp1, type) == 0);
}
if (count == 1)
tmp1[j++] = c;
if (c == ':')
count++;
i++;
}
}
int main(int argc, char *argv[])
{
char s1[50], s2[10];
sprintf(s1, "type:map1|address:localhost|port:27635");
sprintf(s2, "map1");
printf("%d\n", match_type(s1, s2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment