Skip to content

Instantly share code, notes, and snippets.

@yotamN
Forked from anonymous/gist:f429b0765f6ea0de817f
Last active August 29, 2015 14:21
Show Gist options
  • Save yotamN/f0792cb6722d09acb080 to your computer and use it in GitHub Desktop.
Save yotamN/f0792cb6722d09acb080 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
char* PutInStr(const char* fname);
int check(char* sig, char* doc);
int main (int argc, char** argv)
{
char* str = PutInStr(argv[1]);
char* str2 = PutInStr(argv[2]);
if(check(str, str2))
{
printf("same\n");
}
else
{
printf("not same\n");
}
system("PAUSE");
return 0;
}
char* PutInStr(const char* fname)
{
FILE* fp = fopen(fname, "rb");
if (!fp) {
printf("Coudn't open file");
};
long sz;
int i;
char *rtnstr;
fseek(fp, 0, SEEK_END);
sz = ftell(fp);
if (!(rtnstr = (char*)malloc(sizeof(char) * sz)))
{
printf("malloc failed\n");
}
fseek(fp, 0, SEEK_SET);
for (i = 0; i < sz; i++)
{
rtnstr[i] = fgetc(fp);
fclose(fp);
}
return rtnstr;
}
int check(char* sig, char* doc)
{
int i, size, q, same = FALSE, j = 0;
if (strlen(sig) <= strlen(doc))
{
size = strlen(doc);
for (i = 0 ; i < size - strlen(sig); i++)
{
for(j = 0, q=0 ; j<strlen(sig); j++)
{
if(!(sig[j] == doc[i + j]))
{
break;
}
else
{
q++;
}
}
if (q==(strlen(sig) - 1))
{
same = TRUE;
break;
}
printf("%d", j);
}
}
return same;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment