Lainey R.

asked • 11/15/21

Modifying an instance of a struct in C

I am programming in C. I have a structure as defined below:

struct toExecute{

const char **argv;

};

In my main command, I declare an instance of this structure as shown:

int main (){

const char *wc[] = { "wc", 0 };

const char *ls[] = { "ls", "-l", 0 };

const char *sort[] = { "sort", 0 };

struct toExecute commandList [] = { {ls}, {wc} };

return forkP (2, commandList);

}

However, I want to change commandList [1] to {sort} without creating a new instance of a structure. So basically, I want to update commandList after I declared it. It seems like everything I try ends up not working for various reasons. My question is, how do I write a line of code that says commandList.agv[1] = sort?


1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.