write a c programme to count the characters words and lines
in a text book



write a c programme to count the characters words and lines in a text book..

Answer / Narendra Kumar Jaysal

Here's an example C program that counts characters, words, and lines in a file. The program assumes that a word is separated by spaces or newline characters.nn```cn#include <stdio.h>nn#define MAX_SIZE 1024nnint main() {n char text[MAX_SIZE];n int ch, words = 0, lines = 1, characters = 0;nn while ((ch = fgetc(stdin)) != EOF) {n if (ch == 'n') {n lines++;n } else if (ch != ' ' && ch != 't' && ch != 'n') {n characters++;n }n if (ch == ' ' || ch == 't') {n words++;n }n }nn printf("Number of characters: %d
", characters);n printf("Number of words: %d
", words + 1); // +1 for the last unread wordn printf("Number of lines: %d
", lines);n return 0;n}n```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Engineering AllOther Interview Questions

Index of an Array containing 'n' aliment varies from________to_______

1 Answers  


Sorting is not possible by using which of the following methods? (Insertion, Selection, Exchange, Deletion)

2 Answers  


How would Nvidia increase the core clock speed anymore?

1 Answers  


WHY SHOULD I HIRE YOU

1 Answers   Satyam,


Hi All... PLease send me if anyone have "Information Security Officer" Aptitude papers. Please Mail me at mannusanghi@gmail.com

0 Answers  


hi, i applied for AIRPORTS AUTHORITY OF INDIA for the post of AIR TRAFFIC CONTROLLER(ATC)..so plz send me the sample questions to my id...88arun@gmail.com

0 Answers   AAI Airports Authority Of India, Insurance, Nokia,


to which generation of prog. languages does ai prog languages belong

1 Answers   Intel,


question no. 4======Give a brief description of the following terms: a) Play head b) Symbol c) Tweening d) ActionScript e) Frame rate f) Library panel g) Masking h) Context – sensitive Property Inspector i) Bandwidth Profiler j) Frame Label

1 Answers  


As a good company employee, can you report your supervisor to the company management if he or she is going against the company interest in his or her actions?

1 Answers   GE,


when load increase in generator in island mode, why turbine rpm is reduced

1 Answers  


Write a program to input 10 elements in an array and seperate even and odd numbers, positive and negative between them ?

1 Answers  


1 01 101 0101 10101

4 Answers  


Categories
  • Civil Engineering Interview Questions Civil Engineering (5086)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4453)
  • Electrical Engineering Interview Questions Electrical Engineering (16638)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)