realloc - finding reoccuring string in I/O stream -C? -


I am quite new to C. I am trying to write a code that finds a string in the I / O stream, and I do not know what I'm doing wrong I know that the error is probably in the loop in a big time (in the code below) . I want the function to return the location in the bytes from the beginning of the stream and -1 if fails for some reason. It keeps returning -1 for any file. I try it.

  long search_string (const char * str, const char * filename, long offset) {FILE * f = fopen (filename, "r"); If (! F) {return -1; } Int s = 0, c; C = fgetc (f); If (C == EOF) {return -1; } char * check = malloc (sizeof (char)); Fseek (F.L.L., SEEK_END); // and how long the file is long sz = ftell (f); fseek (F.L.L., SEEK_SET); If (fseek (F, offset, SEEK_SET)! = 0) {// Offset return-1 condition is found; } While (fgetc (f)! = EOF) {c = fgetc (f); If (C == SR [0] and F (F) & lt; SG) {check [0] = C; Offset = ftell (f); } S ++; (Unsigned int r = 1; r <(strlen (str)); r ++) {c = fgetc (f); If (c == str [s]) {check = realloc (check, sizeof (char) * s); Check [s] = c; S ++; }} If (strcmp (check, str) == 0) {free (check); Fclose (f); break; } Other {check = reallock (check, size (four)); Offset = -1; }} Offset return;}   

Any help is greatly appreciated

It would be very easy if you memorize the whole file and run it on a standard string search algorithm.

For memory mapping, see:

For the string search code, see:

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -