i don't want to encrypt my running program. So i need to get the name of this one.
Already i'm trying with argv[0] -> looks like "./main". I need to cut the "." from it. Tried with:
char exec_path[PATH_MAX];
for(int i=1; executableName[i]!='\0'; i )
{
exec_path[i-1]=executableName[i];
}
snprintf(exec_path, PATH_MAX, "%s/%s", name, exec_path);
but it returns too many error, and i think there is another nice solution. (maybe a lib?)
Basically, just by adding my argv[0] to the running path, i get this. U can see the problem.
EDIT:
Thanks to all answer, it worked with
memcpy(str, executableName 2, sizeof(executableName));
snprintf(exec_path, PATH_MAX, "%s/%s", name, str);
CodePudding user response:
try this:
char* str = argv[0] 1;
CodePudding user response:
char *ans;
for (int i = strlen(argv[0]); i >=0; i--)
{
if (argv[0][i] == '/')
{
ans = argv[0][i] 1;
break;
}
}