Hey @Rachel-O
I finally figured it out. Sorry, it took me a while. I am not a C developer. But anyways, I have the answer in video format. Check it out. I also included the code down below in case you don't want to watch the video version and just want the answer.
Let me know if you have any questions or if I can be of further help.
#include <stdio.h> #include <stdlib.h> #include <string.h> // Include boolean #include <stdbool.h> int main(int argc, char *argv[]) { // Global variables FILE *input, *output; char c; int sentenceCounter=1,wordCounter=0; // Will be set to true whenever we encounter a period bool newSentence = true; // Make sure input and output files are specified if (argc < 3) { fprintf (output, "\nCorrect usage is: ./mimir.out <name of input file> <name of output file>\n\n"); exit(EXIT_FAILURE); } // Make sure we can open input file if((input = fopen(argv[1], "r")) == NULL) { fprintf (output, "\nUnable to open input file \"%s\".\n\n", argv[1]); exit(EXIT_FAILURE); } // Let's start the process else { // Open output stream output=fopen(argv[2],"w"); // START READING INPUT FILE HERE c = getc(input); // As long as we have not reached the end of the input file while (c != EOF) { // New line marker? if(newSentence){ fprintf (output, "Sentence # %d\n",sentenceCounter++); fprintf (output, "--------------------------------------------------------------------------------\n"); newSentence = false; } // Process a single word while (c != ' ' && c != '\n' && c != ',' && c != '.'){ fprintf(output,"%c", c); c = getc(input); } // We have reached a new line, comma, space or period. So a new word. wordCounter++; // Period encountered. Set new sentence marker if(c == '.'){ newSentence = true; fprintf(output,"\n\n"); } // Have we reached 10 words yet? If so hit a new line. No comma needed. if(wordCounter == 10){ fprintf(output,"\n"); } // Otherwise comma is needed. else if(c == ' ' || c == ',' || c == '\n'){ fprintf(output,", "); } // Reset word counter? if(newSentence || wordCounter == 10){ wordCounter = 0; } // Consume empty space, period, comma and new line while (c == ' ' || c == '.' || c == ',' || c == '\n'){ c = getc(input); } } // End while c != EOF } fclose(input); return 0; }