#### Archived

This topic is now archived and is closed to further replies.

# ClearQuotes()

This topic is 6607 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ive been trying to write a function that accepts an array of chars and takes the first and last character off. So if filename contains: "c:\hi.txt" after this: ClearQuotes(filename); it would then contain c:\hi.txt Im just not good at manipulating string. Could someone help with this little problem, thanks

uh, Anyone?

##### Share on other sites
taking the last character off is simple, just set the last character to 0 (the NUL character is the end-of-string marker in C/C++)
Stripping the first character comes down to incrementing the string-pointer (which is really bad, dont do this!!) or moving every character one step towards the beginning, in effect "pushing" the first character out of the string...
(Perhaps you should test to see that it is actually quotation marks you are removing)...

  char * stripQuotes(char *str){ int len = strlen(str); // Remove first char, moving the whole string: for (int i = 0; i < len-1; ++i) { str = str[i+1]; }; // remove last char: str[len-2] = 0; return str;};

I wrote this straight out of my head now, so it probably won''t work , but you get the idea...

##### Share on other sites
Why do my square brackets in the expression str[ i ] turn into angle brackets > and < ??

it should be:
str[ i ] = str[ i + 1 ];

##### Share on other sites
Of course, if you know that the first and last characters are quotes, it would be simpler to do sscanf(in, "\"[^\"]", out);

##### Share on other sites
How would you use sscanf to do it,
put it in [ source ] [ /source ]. And yeah, The first and last characters are always Quotes.

##### Share on other sites
Since the correct answer isn''t in here, I''ll put it in myself..

The sscanf solution is:
  sscanf(in, "\"%[^\"]", out);

That is, scan and read a quote (\") then read a string (%[^\"]) that has anything except a quote.

// CHRIS

1. 1
2. 2
3. 3
4. 4
frob
15
5. 5

• 16
• 12
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632163
• Total Posts
3004519

×