Total number of words in String File Handling coderinme

Total number of words in String File Handling coderinme

Total number of words in String File Handling coderinme
Write a function to print the count of the words as an independent word in a text file DIALOGUE.TXT.
For example, If the content of the file is “This is his book. Is this book good?”
Then the output should be 8
Here we should make a note that to count the number of words, we always need to count the number of spaces in the whole sentence, then add 1.

#include<stdio.h>
#include<string.h>
int main()
{
FILE *inpt;
int j,count=0,x=0,i=0;
char s[1000],c;
inpt = fopen("Dialogue.txt","a+");
do
{
c = fgetc(inpt);
s[i]=c;
i++;
}
while (c != EOF);
s[i] = '\0';
for(i = 0 ; s[i]!='\0' ; i++)
{
if((s[i]) == ' ')
count++;
}
fprintf(inpt,"\n%d",count+1);
fclose(inpt);
getch();
return 0;
}

For more programs in C, visit our C Coder Archives

Total number of words in String File Handling coderinme

Total number of words in String File Handling coderinme

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

One comment: On Total number of words in String File Handling coderinme

Leave a reply:

Your email address will not be published.