I am trying to run an application in the CMD developer prompt, it should have an input file and output file using command line arguments (which i don't understand, or can't wrap my head around). But when I do it, it's running and ending but nothing is being printed to the output file.
Below is my code with non-relevant code redacted. I don't know if I'm doing something wrong in the code or the cmd line developer prompt.
The app is called printlines.exe and my command looks like this:
printlines.exe -i file.java -o output.txt
Any advice would be greatly appreciated.
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define LINE 1000
void countLines(int *emptyLines, int *totalLines, int *totalComments, char *fileName, FILE *readFile)
{
char line[LINE]; // set array to store input file data
//set variables
readFile = fopen(fileName, "r");
int lines = 0;
int comments = 0;
int empty = 0;
while (fgets(line, LINE, readFile) != NULL) //while loop that reads in input file line by line
{
/*counts lines in input file works when not using
command line arguments redacted to shorten */
}
fclose(readFile);
*emptyLines = empty;
*totalLines = lines;
*totalComments = comments;
}
int main(int argc, char *argv[])
{
FILE *inputFile;
FILE *outputFile;
char *outputName;
char *inputName;
inputName = argv[1];
outputName = argv[2];
inputFile = fopen(inputName, "r");
outputFile = fopen(outputName, "w");
int emptyLines, totalLines, totalComments;
countLines(&emptyLines, &totalLines, &totalComments, inputName, inputFile);
int character;
bool aComment = false;
while ((character = fgetc(inputFile)) != EOF)
{
/* code that writes info from input to output, works
when not using command line arguments redacted to shorten*/
}
//close files
fclose(inputFile);
fclose(outputFile);
printf("There are %d total lines, %d lines of code and %d comments in the file\n", totalLines, emptyLines, totalComments);
return 0;
}