#include #pragma comment(lib, "C:\borland\bcc55\Lib\PSDK\shlwapi.lib") #include /* strの中で最初に現れるcの位置を返す(後から検索) */ char *StrRChar(char *s, const char c) { char *p = s; /* pに文字列の先頭アドレスを保存 */ while (*s != '\0') /* sが文字列の末尾を指すようにする */ s++; /* 検索文字が現れず、かつ、文字列の先頭に達するまでループする */ while (*s != c && p < s) s--; if (*s == c) /* 文字が見つかったら */ return (s); /* その位置を指すポインタを返す */ else /* 見つからなかったら */ return (NULL); /* NULLを返す */ } void SringTrimStart(char *p, char *trim) { char *q = p; do { if (strchr(trim, *q) == NULL) break; q++; } while(1); memmove(p, q, strlen(q) + 1); } void PathGetDirectoryName(void) { char *s = "C:\\MyFolder\\Homepage\\public_html\\C\\PathGetDirectoryName\\PathGetDirectoryName.txt"; char *s1; printf("'%s'からディレクトリ名を取得すると、", s); PathRemoveFileSpec(s); s1 = StrRChar(s, '\\'); SringTrimStart(s1, "\\"); printf("'%s'となる。\n", s1); } int main(void) { PathGetDirectoryName(); return 0; }