Hello, I would like to know how can I print a line from a string, starting from a specific word. I have the following tasks:
Write a program that prints all lines from input that contain a given word.
Only the part of the line starting with the word must be printed.
Prefix it with the line number.
a) Consider only standalone words.
b) Count also occurrences as substrings in other words.
Handle arbitrarily long words.
a) :
Code:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX 100
int main()
{
    char s[MAX];
    char mask[MAX];
    char delim[] = "\n.!?, ";
    char wordString[] = "ana";
    unsigned lineCounter = 0;
    unsigned ok;
    while(fgets(s, sizeof s, stdin))
    {
        //printf("%s", s);
        lineCounter++;
        strcpy(mask, s);
        char* word = strtok(mask, delim);
        while(word != NULL)
        {
            if(strcmp(word, wordString) == 0)
            {
                ok = 1; // if a word on the line coincides with the given word, stop comparing words => ok=1
                break;
            }
            else
            {
                ok = 0; // if ok=0 => there is no word coinciding with the given word on the line
            }
            word = strtok(NULL, delim);
        }
        //printf("%d", ok);
        if(ok == 1)
        {


            printf("%d  %s\n",lineCounter, s);
        }
        else
            printf("The line doesn't contain the given word.\n");
    }
    //printf("There are %d lines in the input.", lineCounter);
    return 0;
}

Input:
andrew goes shopping.
john saw ana in the park
she goes shooping
ana is singing
Output :
The line doesn't contain the given word.
2 john saw ana in the park // this should be just "ana in the park"
The line doesn't contain the given word.
4 ana is singing

I've solved b) in a similar fashion, only using strstr instead of strcmp, they're both working fine, I just want to know how can I print the line starting from the word I want.(I thought maybe I should use a for loop inside the second while and keep track of the position of the first letter of the word, but I think I'm missing an idea).