Qestion: \"Devise a program that counts the number of characters in its input up
ID: 3732955 • Letter: Q
Question
Qestion: "Devise a program that counts the number of characters in its input up to the end of file."
Below is my program. The problem with my program is that my program does not give me the number of characters count. I could not figure out what's wrong with my program.
Please have a look at it and correct it. Thanks a lot for your help!
#include void count_ch(void) int ch; //numofCharacters for counting characters int numOf Characters 0; printf("Please provide the input: "); while ((chgetchar))!EOF) numOfCharacters++; printf(" Number of characters- %d ", num0 f Characters); count ch ifications | Output ch_8HwPau (Run) #11 * ch_8HWPau (Build, Run) #2 ) ch_8HW 1. Character count 2. Character type 3. Better Guess 4 99. Exit Please select number and press enter: Please provide the input: This is the worldExplanation / Answer
#include<stdio.h>
#include<string.h>
void count_ch(void)
{
char ch[10000]; //taking an array of character of size 10000
int numOfCharacters = 0;
printf("Please provide the input: ");
fgets (ch, 10000, stdin); //taking input in array
numOfCharacters = strlen(ch); //calculating length of array using strlen function
printf(" Number of Characters = %d ",numOfCharacters-1); //since last value of every string is so the total length obtained should be subtrated by 1 to get actual length of string
}
int main()
{
count_ch();
}