Sponsored Content
Full Discussion: Need some help with this...
Top Forums Programming Need some help with this... Post 302138235 by porter on Sunday 30th of September 2007 04:16:09 PM
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.
 
All times are GMT -4. The time now is 06:38 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy