I am pretty much done a shell program I have to write for my operating systems class. The only problem is that I can't seem to figure out how to make this function work. It is supposed to separate out a list of tryable paths that is from the getenv("PATH") function and stick each path into an array of character arrays, but on the line of code indicated below, I get a segmentation fault. Anyway the code is below in a text file. I will post everything from the prototype, to the function call, to the function itself. I'm grateful to everybody who can look at it. Once I am done with the program I would be happy to e-mail the source to anyone who would like to take a look at it. Although aggravating, probably one of the cooler programming projects I have been assigned.
Okay so here is the line that I am getting the seg fault on:
while ((*dirs[i] = &strsep(thePath, ':')) != NULL)
Here I am trying to put the first path in the thePath array in the array dirs which will hold all of them seperately.
I have been awake since yesterday at 1, and I am getting really frustrated with this seg fault as well as my professor who has yet to respond to my e-mail asking the same thing I am asking you guys (sent it yesterday at noon).
Re: Problem with a snippet of code in a shell program
Awesome. Just so you guys know I am gathering the relevant parts from throughout my program. It is not bunched up like this in my source of course. Here is the code in the file:
Re: Problem with a snippet of code in a shell program
>*dirs[i] = &strsep(thePath, ':')
Let's look at it like this because it's easier to pick out the errors. dirs is an array of pointer to char. When you subscript dirs, you get a pointer to char, but when you dereference that, you get a single char. So we have this so far as a type map:
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.