Question...
I am writing a program (C++, Carbon, Codewarrior 8, OS X) and I am having difficulty understanding how to handle macintosh paths. The following code should generate a full file name that can be opened by the fopen() command (ansi C), but it does not work.
the first argument (argv[0]) is returning something like
/Volumes/ ...<path>... /MyProgramFile
extracting the path "/Volumes/ ...<path>... /" and adding a file name to the end of it fail when passed to a function like fopen()
e.g.
/Volumes/ ...<path>... /Data.txt
How can I adjust the path such that it is compatible with fopen() or other Ansi C file functions?
Any help would be most appreciated,
Konan
p.s. Here is the pseudo code
int main(int argc, char *argv[])
{
char *FileName = argv[0];
char Path[256];
// extract the path from the full file name
GetPathFromFileName(Path,FileName);
char DataFile[256];
strcpy(DataFile,Path);
strcat(DataFile,"Data.txt");
FILE *InFile = fopen(DataFile,"r");
if (!InFile)
printf("Error opening the file %s\n",DataFile);
... etc....
}
I am writing a program (C++, Carbon, Codewarrior 8, OS X) and I am having difficulty understanding how to handle macintosh paths. The following code should generate a full file name that can be opened by the fopen() command (ansi C), but it does not work.
the first argument (argv[0]) is returning something like
/Volumes/ ...<path>... /MyProgramFile
extracting the path "/Volumes/ ...<path>... /" and adding a file name to the end of it fail when passed to a function like fopen()
e.g.
/Volumes/ ...<path>... /Data.txt
How can I adjust the path such that it is compatible with fopen() or other Ansi C file functions?
Any help would be most appreciated,
Konan
p.s. Here is the pseudo code
int main(int argc, char *argv[])
{
char *FileName = argv[0];
char Path[256];
// extract the path from the full file name
GetPathFromFileName(Path,FileName);
char DataFile[256];
strcpy(DataFile,Path);
strcat(DataFile,"Data.txt");
FILE *InFile = fopen(DataFile,"r");
if (!InFile)
printf("Error opening the file %s\n",DataFile);
... etc....
}