diff --git a/main.c b/main.c index 3859f1d..51a8b26 100644 --- a/main.c +++ b/main.c @@ -257,14 +257,28 @@ int main() free(tokens); } +/** + * returns the index of the File name to redirect output to. + * @param args - an array of all the arguments + * @return int - index whare the fileName is in + */ int getFileNameIndex(char** args) { int i = 0; while(args[i] != NULL) i++; - return i-1; + //we are at the end of the array. + return i-1; //the last arg must be the file name } +/** + * this function will modify th args array, in case of redirecting. + * in that case, the 2 last args are ">" -> "filename" + * so, the function will put Null insted of ">", and will free + * the unneeded array cells. + * @param args - the array of arguments + * @param beforLast - the index of ">" + */ void freeRemainderInArr(char** args, int beforLast) { free(args[beforLast+1]);