Created
May 17, 2015 10:20
-
-
Save anonymous/f429b0765f6ea0de817f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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