simple answer. You can't.
That's because a string is a collection of sequential chars. Each char can be accessed as if it was in an array. For example, say you had string mystring. Then the third char in the string would be mystring.
The code is generating a seg fault. Look at the following code:
if (key == 0)
If this code is supposed to detect that a file has already been opened, shouldn't it be key > 0 ?
Weren't you seeing the seg fault when you ran the code?
If this answers your question, please click on the check mark to accept. ...
Looks like you've got a typo in the signature checking section. you've got
&& (buffer & 0xe0) == 0xe0) when you should have
&& (buffer & 0xf0) == 0xe0)
you have an e where you should have an f.
try changing that and see if you have an improvement