Hick
Hick

Reputation: 36414

how to convert an array of characters in c to a string so as to do string operations on it?

suppose there is a string of characters in an array of d[20] . How to convert to a string d so that i can use it in string functions like strcmp..

Upvotes: 1

Views: 204

Answers (3)

Jack
Jack

Reputation: 133669

it's already something on which you can operate with standard string functions, assuming that it ends with '\0' since it's a requirement: it needs to know when the string ends.

You can prepare the space of char[] by memsetting it with memset(string, 0, length).

Upvotes: 1

user85509
user85509

Reputation: 37702

Null terminate the string. That is, set the character after the last character in your string to zero.

Upvotes: 2

Alex Budovski
Alex Budovski

Reputation: 18456

It must be null-terminated. That's the only requirement. I presume you know how to do that.

Upvotes: 3

Related Questions