2
Hello.
I need to search a word in a text.
#include <stdio.h>
#include <string.h>
int main(void) {
char *word = "dado"; // palavra a ser encontrada
char *pageContent = "Ola tudo bem, vamos jogar dados"; // texto para procurar
char* result = strstr(pageContent, word);
printf("result: %s", result);
return 0;
}
However, in this case it is returning "data". The text contains the word "DATA" but I want to find "DATA", only. How do I find a whole word without it being part of another word? Thank you.
The most general situation is the word to be between spaces. However, it can start at the first position or end at the last, with the corresponding space after or before. The other case you will need to consider is the score. Another thing is whether or not you will differentiate between upper and lower case letters.
– anonimo
Find or return ? In your example the search was supposed to fail because there is not only the word "given" or return only the part "given" ?
– Isac
if it does not find the word it returns NULL, in my example I hope it is returned NULL, because the word 'given' does not exist only 'data'
– boolean
Problem solved? If any response is appropriate you can accept it, or if no solution you can post your own.
– Mateus -- O Schroeder