Need some help with this...


 
Thread Tools Search this Thread
Top Forums Programming Need some help with this...
# 8  
Old 09-30-2007
Quote:
Originally Posted by Legend986
One weird thing is that when I try to print out the elements in the paths array, it says there are atleast 9 but when I use sizeof(paths) I get 4... What could be the reason for this?
You are getting the size of the pointer, not the number of elements in the array.
# 9  
Old 09-30-2007
Code:
int processIt(const char* command,  char* paths[], int numberOfPaths)
{
        /*paths contains the current path to be searched*/
        for(i=0; i<numberOfPaths; i++) {
            char temp[1024];  
            strcpy(temp,paths[i]);  
            strcat(temp,pathsep);
            strcat(temp,command);
            result = access(temp, X_OK);
            if(result != -1)
            {
              printf("%s\t",temp);
              printf("%d\n",result);
            }
        }
        return 0;
  } /* processIt! */

The function has no idea of the number of valid elements in the paths array.
Use strcpy for the first, then strcat to append.
access returns -1 for error, non -1 for success.
X_OK as you want to know the file is executable.
# 10  
Old 09-30-2007
Thank you so much... I followed your advice... And if I want to implement alias support for my command... do I have to add some extra lines to the code or do I just have to utilise the alias command?
# 11  
Old 09-30-2007
Seeing as my manpage for alias does not say where the alias mappings are stored, I think that using popen("alias","r") is your best bet.
# 12  
Old 09-30-2007
Well I don't quite get the sentence itself... What does it mean to implement alias support for my command?
# 13  
Old 09-30-2007
Quote:
Originally Posted by Legend986
What does it mean to implement alias support for my command?
Hm, sounds like the teacher wants you to ......

https://www.unix.com/unix-for-dummies...om-forums.html rule (6)
# 14  
Old 09-30-2007
Not exactly... But my book wants me and its not homework... :P And yeah, don't tell me the solution or anything. I want to implement it myself... I just want to know the meaning of that... thats it..
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question