Continuing from my comment, you need char name[6] = "hello";
to hold 'hello
(plus the nul-terminating character) Even better, you can use
char name[] = "hello";
That will properly initialize name
to contain 6-character (including the nul-byte).
All string.h
functions expect a nul-terminated string as a parameter when they take char *
or const char *
as parameters passed to the functions.
Lastly, as correctly noted in Anuvansh's answer, you cannot use a inequality condition to determine if two strings equal or differ. You either us the normal comparison functions strcmp
, strncmp
, memcmp
or you walk a pointer down each string stopping at the first char the strings differ on, or on the nul-byte if the strings are equivalent.
Look things over and let me know if you have any further questions. Gook luck with your coding.