tags:

views:

25

answers:

2

I am using C. I have a wchar_t pointer which pointing a a file path.

I was wondering, how I can check, whether it is ended with L".xls"?

Any function call I can use?

A: 

Try wcsstr().

D.Shawley
That won't help with something like `file.xls.old`
Thanatos
You are correct there ... `wchar_t *r = wcsstr(str, L".xls"); if (r )
D.Shawley
@D.Shawley: Now it doesn't work for `file.xlsoap.xls` ;)
caf
For precisely what caf mentioned, `wcsstr` is not the function needed here. If the string has a premature `.xls` in it, wcsstr returns info on that, instead of what's at the end of the string, which is what we're really interested in.
Thanatos
This answer is just plain wrong. You could put it in a for loop (`for (r=str; r r=wcsstr(str, L".xls"));` or such but when you could just do like the accepted answer, *why*?
R..
+1  A: 
  • Check that the string is at least 4 long
  • See if the last 4 wchar_t are ".xls"

Thus, this should be it:

if(wcslen(str) >= 4 && wcscmp(str + wcslen(str) - 4, L".xls") == 0)

Thanatos