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
A blank operates as a standalone device and is shared by multiple users
Sedbober [7]
B.s. Hugh gingham thigh hangman
8 0
2 years ago
Read 2 more answers
What are the names of different types of tablets<br>​
jekas [21]

Answer:

iPad

IPad mini

IPad Pro

IPad air

Samsung Galaxy tab

Galaxy Tab e

galaxy tab pro

Galaxy tab 2

Explanation:

Also maybe could you look at my 3 biology questions i really need help

5 0
2 years ago
Sonic the Hedgehog (1991)
e-lub [12.9K]

Answer:

What if we made a fast game?

Explanation:

The mascot is the person, animal or thing which brings good luck, just like Mario. However, this is not a problem with Sonic the Hedgehog. And the Hedgehog is powerful enough to cross any barrier. Hence tieing the collectibles is not required. And the Hedgehog is quite cute and domestic. But it moves only 10 meters per second if we are considering the maximum speed. Hence, the correct option is certainly what if we made a fast game? And this is option C.

7 0
3 years ago
A hacker using information gathered from sniffing network traffic uses your banking credentials from a recent transaction to cre
adell [148]

Answer: a replay attack, a replay attack is used so that the attacker can go sniff out the hash, and get whatever they are trying to get, then once it goes to the attacker it will go back to the original connection after replaying the hash

3 0
2 years ago
Select the correct answer.
ss7ja [257]
The answer a identifying portfolio goal
8 0
3 years ago
Read 2 more answers
Other questions:
  • Describe the role of the microprocessor in an automatic washing<br> machine (IGCSE)
    10·1 answer
  • Why does brainly keep saying “oops... something went wrong! Try again”
    7·2 answers
  • You work for a company that is growing. Originally, all the users in all departments had access to all the data in the database.
    6·2 answers
  • Write a algorithm to attend birthday party​
    8·2 answers
  • Universal Containers uses a custom field on the account object to capture the account credit status. The sales team wants to dis
    7·1 answer
  • Intelligence is to creativity as _____ is to _____. Group of answer choices spatial intelligence; musical intelligence correct t
    15·1 answer
  • Indica si los elementos de las imagenes son una materia prima o un material elaborado
    12·1 answer
  • 1. Who was the first lady programmer?​
    14·2 answers
  • a) pencil b) ink bottle c) polygon d) eye 3. Under which of the following can an operating system be classified? b) software c)
    8·1 answer
  • Information to develop a project network is collected from the.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!