-6

I got a pgm from internet. But I am confused about a code about strlen () function . Is it strlen() replace a string ? I am beginner in this coding .help me .

simple code block below :

while(NULL != fgets(Buffer, 4095, Input))
{
    char *Stop = NULL;
    char *Start = Buffer;

    while(1)
    {

        Stop = strstr(Start, Find);
        if(NULL == Stop)
        {
            fwrite(Start, 1, strlen(Start), Output);
            break;
        }
        printf("\n@found at Line  <%d>",line);
        fwrite(Start, 1, Stop - Start, Output);
        fwrite(Replace, 1, strlen(Replace), Output);
        Start = Stop + strlen(Find);
    }
    line++;
}

why start = stop + strlen(find) replace a string ?

1 Answers1

3

Is it strlen() replace a string ?

No, computes the length of the string passed to it.

why start = stop + strlen(find) replace a string ?

= is called assignment operator, which assigns value of right operand to left operand. a = b; Means value of b is assigned to a. Hope it make sense.

I would suggest pick a text book, first go through basic concepts operators, string, functions and pointers. Then you will understand what exactly your code is doing.

Anil Bhaskar
  • 3,718
  • 4
  • 33
  • 51