- #include <string.h>
- #include <stdio.h>
- //求子串
- char* substr(const char*str, unsigned start, unsigned end)
- {
- unsigned n = end - start;
- static char stbuf[256];
- strncpy(stbuf, str + start, n);
- stbuf[n] = 0; //字串最后加上0
- return stbuf;
- }
- void main()
- {
- char* fileName="F://workspace//zhoulu.wmv";
- char* fileExt;
- char *ptr, c = '.';
- ptr = strrchr(fileName, c); //最后一个出现c的位置
- int pos = ptr-fileName;//用指针相减 求得索引
- fileExt=substr(fileName,pos+1,strlen(fileName));
- printf(fileExt);
- printf("/n");
- }