05/04/04 03:13:01
そのまま貼っちゃいます。今はこんな状態です。
char* dirname(char* path)
{
int pos = strlen(path)-1;
int lastPathSepFoundPos = -1;
static dir[MAX_PATH]="";
while(pos >= 0) {
if (path[pos] == '/' || path[pos] == '\\') {
lastPathSepFoundPos = pos;
break;
}
else pos--;
}
if (lastPathSepFoundPos == -1) return "."; // current dir
else{
strncpy(dir,path,lastPathSepFoundPos);
dir[lastPathSepFoundPos] = 0;
return dir;
}
}
static dir[MAX_PATH]="";をchar dir[MAX_PATH]にすると
→警告「ローカル変数またはテンポラリのアドレスを返します」
となってました。今考えてみれば当然ですよね。。
>>368
どうもです。ちょうど昨日、その2を回避策としてやってみてたとこでした。
その注意というのは関数へのアクセスが同時に起こるような場合でしょうか?
条件コンパイル(#ifdef-#endif)等が面倒になりそうですが、
1の方法が一番簡単そうなので、その方向でやってみることにします。