1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Goshia [24]
3 years ago
9

Write a program in C which will open a text file named Story.txt. You can create the file using any text editor like notepad etc

., and put random words. Make sure the text file is in the same directory as your c program. Next, you need to ask the user for the file name and open the file. Check whether the file is opened successfully or not. If no then continue asking for a correct file name. After the successful opening of the text file, count the number of words and characters (no spaces) in the file. Finally, print the result into the output. You need to create at least 2 user-defined functions.
Computers and Technology
1 answer:
ddd [48]3 years ago
6 0

Answer:

See explaination

Explanation:

#include <stdio.h>

#include <stdlib.h>

int main()

{

FILE * file_object;

char file_name[100];

char ch;

int characters=0, words=0;

printf("Enter source file name: ");

scanf("%s", file_name); //asking user to enter the file name

file_object = fopen(file_name, "r"); //open file in read mode

if (file_object == NULL)

{

printf("\nUnable to open file.file not exist\n"); //check if the file is present or not

}

while ((ch = fgetc(file_object)) != EOF) //read each character till the end of the file

{

if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\0') //if character is space or tab or new line or null character increment word count

words++;

else

characters++; //else increment character count this assures that there is no spaces count

}

printf("The file story.txt has the following Statistics:\n"); //finally print the final statistics

if (characters > 0)

{

printf("Words: %d\n", words+1); //for last word purpose just increment the count of words

printf("Characters (no spaces): %d\n", characters);

}

fclose(file_object); //close the file object

return 0;

}

You might be interested in
Long Answer Questions: a. Briefly explain the types of Control Structures in QBASIC.​
Alexus [3.1K]

Answer:

The three basic types of control structures are sequential, selection and iteration. They can be combined in any way to solve a specified problem. Sequential is the default control structure, statements are executed line by line in the order in which they appear.

7 0
3 years ago
What three components should be included in a computer that is used to create TV commercials and music videos? (Choose three.
Vikki [24]

The three components is a specialized video card, large and fast hard drives and specialized audio card.

8 0
3 years ago
Read 2 more answers
Which is the best tip for optimizing a TrueView video for viewer engagement?
Ivenika [448]

Answer: (A) Look at engagement rate for targeting and focus on the methods with the highest view through rate

Explanation:

TrueView video enables to post ads in social sites however it is paid by the sponsor only if the ad is viewed fully or in some cases it is viewed only upto 30s of the total size of the video.

So in order to have a larger viewer engagement it is necessary for it to focus on the methods which would garner it highest views.

So option A is correct.

Option B and c are not correct these options would not cater to the needs of the viewer.

5 0
3 years ago
In a game with three frames, where will the objects on Layer 1 appear?
Ivan
It’s between d or c
6 0
3 years ago
Read 2 more answers
When Mary started college, her parents bought her a new computer that came loaded with the bare essentials in terms of software
Darina [25.2K]

Answer:

office online

Explanation:

office online is a free online version of Microsoft office suite. it includes Microsoft word, Microsoft excel,  Microsoft power point, one note. It allows users to create and edit files online.

5 0
3 years ago
Other questions:
  • General Hardware Products Your boss, the IT director, wants you to explain FDDs, BPM, DFDs, and UML to a group of company manage
    13·1 answer
  • Write a C program that has the following statements: int a, b; a = 10; b = a + fun(); printf("With the function call on the righ
    12·1 answer
  • What is the correct order of network types when categorized by their size or the physical area they cover, from largest to small
    10·1 answer
  • A __________ network is good for connecting computers over boundaries.
    6·2 answers
  • Why it’s important to keep the standard internet protocol TCP/IP?
    11·1 answer
  • Which of the following is used by credit card companies to determine APR?
    10·2 answers
  • ________models software in terms similar to those that people use to describe real- world objects.
    6·1 answer
  • Advantages and disadvantages of java
    10·1 answer
  • What is a critical consideration on using cloud-based file sharing and storage applications.
    15·1 answer
  • During the maintenance phase of the sdlc, the team must _____ if a system's objectives are not being met
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!