Question: The C code below opens and reads a file, changing the Case, It also counts the number of words and sentences in the opened file.

The C code below opens and reads a file, changing the Case, It also counts the number of words and sentences in the opened file. Seperate the code into three different files that open each other, working the same functions, and give the same output as the original.

1. driver.c This is where main will be located.

2. functions.h This is where your function prototypes will reside.

3. Functions.c This is where you will implement you functions.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

#include

#include

int word=0;

int sentence=0;

char output[1000];

int outputCounter=0;

void changeCase(char* s);

void wordCount(char *a);

void sentenceCount(char *a);

int main()

{

FILE * fpRead;

FILE * fpWrite;

char line[500];

fpRead = fopen("input.txt", "r");

fpWrite = fopen("output.txt","w");

if (fpRead == NULL) exit(EXIT_FAILURE);

while ( fgets ( line, 128,fpRead ) != NULL )

{

wordCount(line);

sentenceCount(line);

changeCase(line);

}

fprintf(fpWrite,"%s",output);

fclose(fpRead);

fclose(fpWrite);

fpRead = fopen("output.txt", "r");

while ( fgets ( line, 128,fpRead ) != NULL )

printf("%s",line);

word++;

fclose(fpRead);

printf(" Word_Count is: %d ",word);

printf("Sentence_Count is: %d ",sentence);

return 0;

}

void wordCount(char *a)

{

int i;

for(i=0;a[i]!='\0';i++)

{

if(a[i]!=' ' && a[i+1]==' ')

word=word+1;

}

}

void sentenceCount(char *ch)

{

int i;

for(i=0;ch[i]!='\0';i++)

{

if(ch[i] == '.' || ch[i] == '?' || ch[i] == '!')

sentence++;

}

}

void changeCase(char *s)

{

int c;

for(c=0;s[c]!='\0';c++)

{

if (s[c] >= 'A' && s[c] <= 'Z')

s[c] = s[c] + 32;

else if (s[c] >= 'a' && s[c] <= 'z')

s[c] = s[c] - 32;

output[outputCounter++]=s[c];

}

output[outputCounter++];

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!