ClearQuotes()
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
July 16, 2000 07:18 PM
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)...
I wrote this straight out of my head now, so it probably won''t work , but you get the idea...
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<i> = 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...
July 16, 2000 07:20 PM
Why do my square brackets in the expression str turn into angle brackets > and < ??<br><br>it should be:<br>str = str;<br>
Of course, if you know that the first and last characters are quotes, it would be simpler to do sscanf(in, "\"[^\"]", out);
How would you use sscanf to do it,
put it in [ source ] [ /source ]. And yeah, The first and last characters are always Quotes.
put it in [ source ] [ /source ]. And yeah, The first and last characters are always Quotes.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement