Hello,
I am new to this. Hope I won't break any etiquette unknowingly. I DID my homework, I believe ...
I'd like to get C/C++ code which allows me to get the path of the active application, ideally in the format of char. I wrote a program for which I want to retrieve info from a txt file (specific parameters) and also to save data in a txt file. Since I would like to use this program on a variety of Macs, I'd like it to be able to automatically retrieve the path so no matter what it'll find the parameter.txt file and the savedata.txt file.
I am using Macintosh computers with OS X (10.4.8), Metrowerk's CodeWarrior C/C++, and Carbon platform (until I learn cocoa).
Here's sample code I had hoped would do the job but it doesn't because I don't know what an "environment variable" is (i.e. how to define one, how to use it). Maybe to use getenv is totally wrong?
#include <stdio.h>
#include <stdlib.h>
int main ()
{
char *value;
char *var;
if( (value = getenv(var)) == NULL)
{ printf("%s is not an environmental variable", var);}
else
{ printf("%s = %s \n", var, value);} // I hoped that var would contain the path.
return 0;
}
Thanks for your patience and any help you might be able to offer!
BP