Answer:
The C program for characters will be like the one below:
Step-by-step explanation:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE * file;
char path[100];
char ch;
int characters, words, lines;
/* Input path of files to merge to third file */
printf("Enter source file path: ");
scanf("%s", path);
/* Open source files in 'r' mode */
file = fopen(path, "r");
/* Check if file opened successfully */
if (file == NULL)
{
printf("\\Unable to open file.\\");
printf("Please check if file exists and you have read privilege.\\");
exit(EXIT_FAILURE);
}
/*
* Logic to count characters, words and lines.
*/
characters = words = lines = 0;
while ((ch = fgetc(file)) != EOF)
ch == '\0')
words++;
/* Increment words and lines for last word */
if (characters > 0)
{
words++;
lines++;
}
/* Print file statistics */
printf("\\");
printf("Total characters = %d\\", characters);
printf("Total words = %d\\", words);
printf("Total lines = %d\\", lines);
/* Close files to release resources */
fclose(file);
return 0;
}