You are on page 1of 1

Expert Q&A

Find solutions to your homework Search

Question Post a question


Get step-by-step solutions to help you
C Programming better understand your homework

20 questions left - Renews Dec. 22, 2022


• File summary
- write codes using le I/O Enter question
• read from a text le (E3-4.txt)
• count the number of characters
- with space or terminators (' ' '\t' '\r' '\n' ',' ';' '.' '?' '!')
- without space or terminators (' ' '\t' '\r' '\n' ',' ';' '.' '?' '!')
Continue to post
• count the number of words
• count the number of lines

My Textbook Solutions

Investment Analysis an…


 
Solutions ➔

Successful Project Man…


 
Solutions ➔

View all solutions

Show transcribed data

Expert Answer
Anonymous answered this
141 answers

#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *fptr;
fptr = fopen("E3-4.txt", "r");
if (fptr == NULL)
{
printf("\nCan't open file or file doesn't exist.");
exit(0);
}
int char_Count = 0;
int char_Count1 = 0;
int wrd_count = 0;
int line_count = 0;
int ch;
while ((ch = getc(fptr)) != EOF)
{
char x = (char)ch;
char_Count++;
if (x >= 'a' && x <= 'z')
char_Count1++;
if (x == ' ' || x == '\n')
{
wrd_count++;
}
if (x == '\n')
{
line_count++;
}
}
printf("Character count with all characters = %d\n", char_Count);
printf("Character count excluding the given characters = %d\n", char_Count1);
printf("Word count = %d\n", wrd_count);
printf("Line count = %d\n", line_count);
fclose(fptr);
return 0;
}

Was this answer helpful? 0 0

Questions viewed by other students


Q: plaese answer by the code
A: See answer

Q: C ProgrammingCharacter search in a stringwrite codes using string• input 1: any string in a


character array s• input 2: any character c• search the rst occurrence of c in s, output its array
indexsearch the last occurrence of c in s, output its array index• if c does not exist in s, output a
message "Not found!"
A: See answer

Show more

COMPANY LEGAL & POLICIES CHEGG PRODUCTS AND SERVICES CHEGG NETWORK CUSTOMER SERVICE
About Chegg Advertising Choices Cheap Textbooks Chegg Math Solver Easybib Customer Service
Chegg For Good Cookie Notice Chegg Coupon Mobile Apps Internships.com Give Us Feedback
College Marketing General Policies Chegg Play Solutions Manual Thinkful Manage Subscription
Corporate Development Intellectual Property Rights Chegg Study Help Study 101 Busuu
Investor Relations Terms of Use College Textbooks Textbook Rental Mathway
Jobs Global Privacy Policy eTextbooks Used Textbooks
Join Our Affiliate Program Cookies Settings Flashcards Digital Access Codes
Media Center Honor Code Learn Chegg Life
Site Map Honor Shield Uversity Chegg Writing
Academic Integrity

© 2003-2022 Chegg Inc. All rights reserved.

You might also like