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
When you need to switch on an electrical current at a remote location, would you use a relay or an amplifier?
ahrayia [7]

Answer:

Relay

Explanation:

They both perform similar functions in terms of control of voltage and current but the relay would be better because although it cannot produce a variable output like that of an amplifier, it has the capacity to isolate its input from its output.

7 0
2 years ago
What kind of company would hire an Information Support and Service employee?
andrew-mc [135]

Answer:

THE GANG IS A GANG AND A GANG IS A GANG

Explanation:

4 0
2 years ago
What is desktop computer? <br> ​
butalik [34]

Answer:

a computer suitable for use at an ordinary desk.

noun: desktop computer

"a new low-end desktop"

Explanation:

please mark me as a brainly

3 0
2 years ago
Read 3 more answers
What is the most common form of renewable energy used to generate electricity
sertanlavr [38]

i think that it’s either sunlight or solar energy

6 0
2 years ago
Which one of the following is the correct code snippet for calculating the largest value in an integer array list aList?
vodka [1.7K]

Answer:

Option a.  int max = aList.get(0); for (int count = 1; count < aList.size(); count++) { if (aList.get(count) > max) { max = aList.get(count); } }

is the correct code snippet.

Explanation:

Following is given the explanation for the code snippet to find largest value in an integer array list aList.

  1. From the array list aList, very first element having index 0 will be stored in the variable max (having data type int).
  2. By using for starting from count =1 to count = size of array (aList), we will compare each element of the array with first element of the array.
  3. If any of the checked element get greater from the first element, it gets replaced in the variable max and the count is increased by 1 so that the next element may be checked.
  4. When the loop will end, the variable max will have the greatest value from the array aList.

i hope it will help you!

7 0
3 years ago
Read 2 more answers
Other questions:
  • The support group at Universal Containers wants agents to capture different information for product support and inquiry cases. I
    14·1 answer
  • Which ones are right
    15·1 answer
  • Describe the difference between the while loop and the do-while loop.
    7·1 answer
  • How do you get a code in C to count down from 5??
    6·1 answer
  • Ms. Osteen gives her class an assignment to insert background color that gradually changes from blue to green. To accomplish thi
    8·1 answer
  • What is the main purpose of a web crawling program
    15·1 answer
  • Please help me I don't understand. It's Python.
    5·2 answers
  • How many times would the code in this loop repeat? ____________ for ( j = 0; j &lt; 10; j++ ) { appendItem (myList, aNumber); }
    9·1 answer
  • With a(n) ____ you can arrive at a scene, acquire the data you need, and return to the lab as quickly as possible.
    14·1 answer
  • What are the two protocols used most often with iot devices? (select two. )
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!