1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
void removeFromPath()
{
char field [32];
char *stringPtr;
char *pathPtr;
char firstpass = 'y';
int n;
strcpy(pathPtr,dirPath);
stringPtr=pathPtr;
char *tempBuf=(char *)malloc((strlen(dirPath)+1));
strcpy(dirPath,tempBuf);
while ( sscanf(stringPtr, "%31[^:]%n", field, &n) == 1 )
{
//need to build new path variable removing the path specified
if(strcmp((const char *)field,(const char *)cmds[2])==0)
{
//do nothing, to drop off addition
}
else
{
if ( firstpass == 'y')
{
strcat(tempBuf,field);
firstpass = 'n';
}
else
{
strcat(tempBuf,":");
strcat(tempBuf,field);
}
}
stringPtr +=n;
++stringPtr;
}//end while()
//clear variables
strcpy(cmds[0],"");
strcpy(cmds[1],"");
strcpy(cmds[2],"");
strcpy(dirPath,tempBuf);
tempBuf="";
field[0]scanf('\0';
//firstpass='';
printf("PATH:%s\n",dirPath);
}//end removeFromPath()
|