<string.h> header isn't working. Please Help


#1

Hey guys,

I dont understand what is happening. I am just looking to use the string functions and its not highlighting or understanding the functions I want it to do. It seems as though #include string.h is not working.
This is an example of what won’t work:

include stdio.h
include cs50.h
include string.h

(THE INCLUDE HEADERS DO HAVE # and < > THEY JUST WONT SHOW IN THIS FORUM IF I PUT THEM THERE)

int main(void)
{
printf(“What is your name?”)
string s1 = GetString();
}

and I get:

name.c:9:12: error: unused variable ‘s1’ [-Werror,-Wunused-variable]
string s1 = GetString();
^
1 error generated.
make: *** [name] Error 1


#2

I take a wild guess here, but string is not a type. If you want a “string” it is an array of single characters.

Cheers.


#3

Its odd though as I’ve tried removing string.h and adding a few others and none of them will allow me to use the function GetString(). Ive also tried copying other code that works and uses strings but it won’t work when I try compile it.


#4

Again, the problem is not the library string.h. The problem is that string is not a valid type in C. char is valid, but not string. The compiler error tells you that it doesn’t recognise what “string” is. You may or may not miss a typedef. I’m not sure where you got the code from, but you haven’t written it yourself.

And string.h doesn’t contain a GetString method last time I’ve checked (but this is 10 years ago).

Google and StackOverflow are your friends.

Have fun.