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]
4 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]4 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
Reputable firms often ask recent graduates to pay an up-front fee for a job.
wolverine [178]

Answer:

What is your question?

Explanation:

7 0
3 years ago
Read 2 more answers
What statement best describes operating systems?
GenaCL600 [577]

Answer:

An operating system, or "OS," is software that communicates with the hardware and allows other programs to run

3 0
3 years ago
It is illegal to have __________ emergency lights on your vehicle.
Alexxx [7]

Answer is A. Red and Blue

This because these are the same color of emergency lights that are used on Emergency vehicles like ambulances, police cars, fire trucks, etc. We wouldn't want normal citizens confusing drivers with police officers in case of an actual emergency.

8 0
3 years ago
Read 2 more answers
Write Python code to save the data to a MongoDB collection:Import json module to parse JSON dataImport MongoClient from pymongo
Zigmanuir [339]

Answer:

Explanation:

The objective of this task is to compute a program that involves the usage of Python code to save the data to MongoDB and to query  the database.

Due to the error that occur which makes me to be unable to submit this answer, I've created a word document instead and the attached file can be found below.

Thanks!

Download docx
8 0
3 years ago
The WITH CHECK OPTION clause _________.a. prevents a row in a view form being updated if that would cause the row to be excluded
Finger [1]

Answer:

The correct answer to the following question will be Option A.

Explanation:

For such a standards-compliant perspective, the WITH CHECK OPTION clause could be provided to prohibit additions to rows under which the select statement WHERE clause is sometimes not valid.

  • This also prevents changes to rows under which the WHERE clause becomes accurate but perhaps the change will result in it not being valid.
  • It helps to prevent updating of a row throughout a view process if this causes the row to still be omitted from those in the display.
5 0
3 years ago
Other questions:
  • A*+(B+c|3) how do you figure out the coding for this
    14·1 answer
  • Why do nonprofit agencies often include blogs on their websites?
    5·1 answer
  • To move one screen to the left press ____.
    9·1 answer
  • Use induction on n to prove that fir all n&gt;=2, 2^n+3^n&lt;5^n
    11·1 answer
  • On a camera,what does focus tracking do?
    6·1 answer
  • Why might it be a good idea to choose a bus topology?
    6·2 answers
  • Witch of the following is a malicious program that can replicate and spread from computer to computer?
    13·1 answer
  • Five Star Retro Video rents VHS tapes and DVDs to the same connoisseurs who like to buy LP record albums. The store rents new vi
    13·1 answer
  • Select the correct answer.
    10·1 answer
  • If you are connected to a network that uses DHCP, and you need to terminate your Windows workstation's DHCP lease, which command
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!