Mark said:
well shark,
if that's the case, how might i do what i asked with cstrings?
Well, what good does a pointer to a character in a c-style string do you?
If you must absolutely use c-style strings (don't, std::strings are SO much
better) pointer manipulation was something you had to cope with.
Basically, though, strcpy (string copy) takes two pointers. A pointer from
where to copy to, and a pointer from where to copy from. So if you had a
pointer to the . in "c:\hello.txt" you could use strcpy starting from the
't' in txt to get the extention by adding one to your pointer. Something
like:
char MyString[] = "c:\\hello.txt";
char* Period = strrchr(MyString, '.');
char Ext[10] = "";
strcpy( Ext, Period + 1 ); // Adding one to pointer makes it point to 't'
// It will copy to the first null char.
Now, if you wanted the beginning, you would use strncpy (string number copy)
which takes how many characters to copy. Again, 2 pointers. IIRC the parms
are copy to, copy from, number of chars. So you do:
char FileName[100] = "";
strncpy( FileName, MyString, Period - FileName );
This uses pointer math to determine how many characters to copy.
Again though, forget all this and use std::string. It is so freaking easy
to get pointer math wrong or confuse yourself as to what your pointers are
pointing to and wind up with buffer overflows which are a major pain in the
neck to find.