bouzinabdotcom/CCommentator

Allow stdin and stdout as input and output

Closed this issue · 1 comments

Allow program user to use stdin andstdout as input and output in order to take advantage of the shell's piping/redirection. Being hard-coded to actual file is a bit overly restrictive. For example, I should be able to do $./ccommentator < main.c to see the output shown on screen without the necessity of writing the output to a file.

Fixed this by altering the parse_args function as follows :

case 1:  //if only one arg is suplied (executable name) 
            // use standard io 

            //use filename as a flag to communicate the use of std io
            *filename = (char*) malloc((strlen("std")+1)*sizeof(char));

            strcpy(*filename, "std");
            break;

Then in main if filename is "std" removeCode is called using stdin and stdout (just to preserve previous way of doing it otherwise I could've neglected the use for parse_args and used stdin and stdout from the get go).

if(strcmp(filename, "std")==0)
        removeCode(stdin, stdout);
    
    else
        removeCode(open_iofile(filename, 0), open_iofile(newfilename, 1)); //remove code