Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6201091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:29:28+00:00 2026-05-24T04:29:28+00:00

The function below takes the argv[0] argument that contains the calling path of the

  • 0

The function below takes the argv[0] argument that contains the calling path of the application and replaces the last bit until it hits a “/” with the name of the new app I want to spawn that sits in the same folder.

BTW: I’m declaring a global argv variable so the function can have access to it because I did not want to pass the info in every function call.

When I compile my code, all seems to work, but I get the above warning.

I know that I’m declaring the variable and that as soon as the function returns it will be destroyed.

Being a beginner C programmer I wanted to know what the most elegant/easiest way of solving this problem would be?

Should I pass a pointer to the function or malloc some memory?

char *returnFullPath()
{
    char pathToApp[strlen(argv[0])+1];
    strcpy(pathToApp, argv[0]);
    int path_length = strlen(argv[0]);

    while (pathToApp[path_length] != '/')
    {
        path_length--;
    }

    if (path_length > 2)
        pathToApp[path_length+1] = '\0';
    else
        pathToApp[0] = '\0';

    // length of getcwd + length of pathtoapp + 1 for zero plus 6 for "bidbot"
    char bidbotPath[strlen(getcwd(NULL,0)) + strlen(pathToApp) + 1 + 6];

    sprintf(bidbotPath, "%s/%sbidbot", getcwd(NULL,0), pathToApp);

    return bidbotPath;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:29:30+00:00Added an answer on May 24, 2026 at 4:29 am

    Some other answers suggest that you malloc something and return it. This is bad practice in the same sense as in C++, when you new something in a function and the caller is supposed to delete it (who has ownership?)

    There is a reason that many C APIs have the format of:

    function(buf, length);
    

    Meaning that the CALLER supplies the buffer and how long it is. IT is the caller’s responsibility to allocate and de-allocate this buffer and your function should use it, and check that you’re not going to overflow the length.

    Do not malloc and return. It’s just asking for trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using my zip function(see below), write a function addpairs that takes two lists [x0;
I have written a function below that takes a pointer to the front of
I have this function below that takes a list of id's and searches the
The function below takes a python file handle, reads in packed binary data from
Below is my function that will take a timestamp and tell you the time
The function below takes the test-backup.ini file, parses it and inputs the values into
I am trying to create a function guilabel_wrap(char *buffer, int maxlen) that takes a
The below function takes in a array of char pointers Eg : arr[0]: ls
I have created a function that takes a SQL command and produces output that
I'm working on a function that takes the stage mouse coordinates in Flash AS3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.