3

I need to reproduce behavior of strnstr function. I want to test strnstr but can't compile program, its written "implicit declaration of function strnstr [-Wimplicit-function-declaration]" and "undefined reference to strnstr". I included header <string.h>.

I know that strnstr() isn't in standard library and the problem is probably connected with compiler, but how to fix it to work with strnstr()?

Compiler version: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609

unwind
  • 391,730
  • 64
  • 469
  • 606
ivoriik
  • 155
  • 1
  • 11

1 Answers1

5

There's no function named strnstr in standard C or POSIX. It's not in glibc/Linux either. It appears to be FreeBSD function.

I know that strnstr() isn't in standard library and the problem is probably connected with compiler, but how to fix it to work with strnstr()?

Not sure why you think it's a compiler issue (unless you think it's a compiler intrinsic). If it's not provided by your C library, it's just not available.

So if it's not available on your system (probably you are not using a BSD system) then you can implement it. You can look at an existing implementation.

P.P
  • 117,907
  • 20
  • 175
  • 238