2 Replies - 304 Views - Last Post: 08 October 2012 - 10:11 PM Rate Topic: -----

#1 miked89  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 04-October 12

building a shell: Comparing values in an array of pointers

Posted 08 October 2012 - 07:54 PM

Hello Friends,

I am building a shell that has to handle cd and ls as a built in.
The basic design is this
forever
issue prompt
parse
react to results of parse
repeat

My plan is to have parse set flags when certain situations occur. For instance when the user enters
cd i want to set a flag and respond to it once parse returns to main.

My problem right now is catching the situation when the user types cd.

//Parse function
void parse(char *t,char **ptrArray)
{
int isBackground = 0;
int j=0;
int i, ch;
ptrArray[0] = t ;
int c;
 
for(;;)/>{


c = getword(t);    //returns the integer length of the word typed. Getword also stores the characters in an array


if(c ==-1){
printf("p2 has terminated due to EOF");
exit(0);
}

if(c ==0){

j++;
ptrArray[j]= NULL;
return;
}

if(ptrArray[0] == "cd"){         //Here is where my question lies
setFlag =1;
}

t = t  + c +1;
j++;
ptrArray[j] = t;

}}




It doesnt appear that my program is actually reacting to this when i run it. Am i misunderstanding something with arrays of pointers here?

Any help would be greatly appreciated

Thanks,
Mike

Is This A Good Question/Topic? 0
  • +

Replies To: building a shell: Comparing values in an array of pointers

#2 rfs02  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 26
  • View blog
  • Posts: 70
  • Joined: 30-September 12

Re: building a shell: Comparing values in an array of pointers

Posted 08 October 2012 - 09:14 PM

Your line 28 is checking whether the pointers are the same (which they are guaranteed not to be).

You need to use strcmp or a variant.
Was This Post Helpful? 0
  • +
  • -

#3 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1770
  • View blog
  • Posts: 3,428
  • Joined: 30-May 10

Re: building a shell: Comparing values in an array of pointers

Posted 08 October 2012 - 10:11 PM

Your code is awful to read.
http://sourceforge.n...tle=Indentation
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1