В C найти позицию подстроки в строке

Вот программа для приема:

  1. Предложение от пользователя.
  2. Слово от пользователя.

Как найти место вставленного слова в предложении?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char sntnc[50], word[50], *ptr[50];
    int pos;
    puts("\nEnter a sentence");
    gets(sntnc);
    fflush(stdin);
    puts("\nEnter a word");
    gets(word);
    fflush(stdin);
    ptr=strstr(sntnc,word);

    //how do I find out at what position the word occurs in the sentence?

    //Following is the required output
    printf("The word starts at position #%d", pos);
    return 0;
}
7
задан the Tin Man 6 August 2012 в 22:04
поделиться