in Education by
Using the readlink function used as a solution to How do I find the location of the executable in C?, how would I get the path into a char array? Also, what do the variables buf and bufsize represent and how do I initialize them? EDIT: I am trying to get the path of the currently running program, just like the question linked above. The answer to that question said to use readlink("proc/self/exe"). I do not know how to implement that into my program. I tried: char buf[1024]; string var = readlink("/proc/self/exe", buf, bufsize); This is obviously incorrect. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This Use the readlink() function properly for the correct uses of the readlink function. If you have your path in a std::string, you could do something like this: #include #include std::string do_readlink(std::string const& path) { char buff[PATH_MAX]; ssize_t len = ::readlink(path.c_str(), buff, sizeof(buff)-1); if (len != -1) { buff[len] = '\0'; return std::string(buff); } /* handle error condition */ } If you're only after a fixed path: std::string get_selfpath() { char buff[PATH_MAX]; ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1); if (len != -1) { buff[len] = '\0'; return std::string(buff); } /* handle error condition */ } To use it: int main() { std::string selfpath = get_selfpath(); std::cout << selfpath << std::endl; return 0; }

Related questions

0 votes
    I doubt it can be done portably, but are there any solutions out there? I think it could be done ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    Write the syntax to set the path of the current working directory in R environment? (a) Setwd( dipath ) ... Debugging of R Programming Select the correct answer from above options...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Which function is difficult to implement? (a) Lapply (b) Japply (c) Vapply (d) Zapply I have been asked ... Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which function in R language is used to find out whether the means of 2 groups are equal to each other ... Debugging of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Which of the following is used to find variance of all values? (a) var() (b) sd() (c) mean() ... Linear Regression of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Which of the following groups find the correlation matrix? (a) factor.model (b) col.max(x) (c) stem ( ... Regression of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Which of the following statement find cases with no missing values? (a) complete...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    The error ; Execution error (SunCertPathBuilderException) at sun.security.provider.certpath.SunCertPathBuilder/build ( ... Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
0 votes
    In which search problem, to find the shortest path, each city must be visited once only? Map coloring ... path between a source and a destination Travelling Salesman problem...
asked Mar 8, 2021 in Technology by JackTerrance
0 votes
    I want to be able to zoom in my QtCharts using the mouse. The best way to zoom using the mouse ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 6, 2022 in Education by JackTerrance
0 votes
    According to my understanding of QDateEdit's API documentation it creates a widget for editing dates. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    I need to render a vector-only SVG without antialiasing in Qt; specifically, I don't want the resulting ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    According to my understanding of QDateEdit's API documentation it creates a widget for editing dates. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    According to my understanding of QDateEdit's API documentation it creates a widget for editing dates. The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
...