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
You were fortunate to get the ice off of the wings, but whatever caused the cabin to depressurize also vented all of your fuel o
torisob [31]

Answer:

A speed govenor

Explanation:

speed governor is an electronic device linked to the gearbox where sensors capture the movement of the vehicle. If the vehicle exceeds the specified speed limit, the device automatically slows the vehicle.

4 0
3 years ago
The procurement department of an organization helps to program software. <br> A)True<br> B)False
valina [46]
I think it is true absolutely
8 0
2 years ago
Read 2 more answers
How to use github to creat a blog?Thank you
stepan [7]
You can use GitHub Pages! They have tutorials on their site to help you set up using that (too much for this format!). You can use it to make your own personal site, as well as host any existing site you may have.
5 0
3 years ago
Who developed one of the first mathematical models of a multilevel security computer system?
svp [43]

Answer:

C. Bell and LaPadula

Explanation:

The first mathematical models of multilevel security computer system was developed by Bell and Lapadula. Their full names are David Elliot Bell and Leonard J. Lapadula. Their model used to define the concept of modes of access,secure state machine and outlined the rules of access.

6 0
2 years ago
Which tools allows you to see the edition, version and memory use by windows 10?
cricket20 [7]

Answer:

Resource Monitor

Performance Monitor

Computer Management and Administrative Tools

Advanced User Accounts Tool

Disk Cleanup

Local Group Policy Editor

There is alot do u want them all?

6 0
3 years ago
Other questions:
  • Where should you look for most objective and unbaised information
    15·1 answer
  • An essential skill today is knowing how to cite sources properly. Creative Commons has a system of licenses and tools for creato
    11·1 answer
  • Which database is more secure: the java-based apache derby or mysql?
    6·1 answer
  • How to engage more underrepresented and under resourced students in stem programs?
    10·1 answer
  • When someone refers to "space" on a computer or device, they are usually referring to _____, which allows the user to save a fil
    10·1 answer
  • Jack has a fear of getting up in front of a group of people and giving a presentation. When he gave his last presentation, he ta
    5·2 answers
  • Write a function called printBackwards() that will work with a C string. The function will print any C string backwards. You don
    13·1 answer
  • BRAINLIEST !!A game design document is like a diary for game developers.
    11·1 answer
  • Which of the following can ensily reverse motion and are better at varying speeds than electrical motors?
    10·1 answer
  • Find the total cost of a $125 coat purchased in Los Angeles County where the sales tax is 9%. Use the expression c + 0.09c
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!