There's a memory corruption somewhere in your code, in a part you probably didn't show. Since your snippet isn't valid C, I assume you typed it manually or copied it incomplete.
To debug such scenarios, if you are on a platform that supports it (as you are), use either DrMemory or Valgrind. I prefer Valgrind for its features, whereas DrMemory is arguably faster.
Both programs will be able to pinpoint the problem and even attach you to a debugger while the problematic program is still running. So you can inspect error conditions within the live program.
Side-note: if you don't have to assemble the name in any way, you can pass it as a literal string to gethostbyname
:
struct hostent *host;
host = (struct hostent *) gethostbyname("localhost");