Need some help with this...


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 8  
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  
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  
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  
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  
Well I don't quite get the sentence itself... What does it mean to implement alias support for my command?
# 13  
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  
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 for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #209
Difficulty: Medium
The development work for OSPF prior to its publication as open standard was undertaken largely by the Digital Equipment Corporation.
True or False?

Featured Tech Videos