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
Write a note on secondary storage​
12345 [234]
Secondary storage refers to storage devices and media that are not constantly accessible by a computer system. Examples include external hard drives, portable flash drives, CDs, and DVDs.
good luck
4 0
4 years ago
Can someone help me with this error? Will give brainliest and i will give more details if you need just please help​
liubo4ka [24]

Answer:

From what I see, you're trying to convert an int to a double&. This is illegal. Do you have any arrays with ints?

8 0
3 years ago
what is the the process of sending a packet from one host to a selected group of hosts, possibly in different networks?
Burka [1]
I believe it's "multicast"
6 0
3 years ago
Explain in details the evolution of computers​
Colt1911 [192]

Answer:

Evolution of computer technology can be divided into five generations. First generation computer consisted of vacuum tubes and they were used from 1943-1958. ... Third generation (1966-1973) computer consisted of integrated circuits (IC) i.e. many transistors in single silicon chip.

<em><u> </u></em><em><u>.</u></em><em><u>.</u></em><em><u>.</u></em><em><u>.</u></em><em><u> </u></em><em><u>Mark as brilliant</u></em><em><u>.</u></em><em><u>.</u></em><em><u>.</u></em><em><u>.</u></em><em><u>.</u></em><em><u>.</u></em><em><u> </u></em>

3 0
3 years ago
What information is displayed in the message header of a received message? Check all that apply.
Aleks04 [339]

Answer:

the subject of the message

the sender's name

the recipient's name

the date and time when the message was received

Explanation:

Various information is displayed in the header of the message of a received message. And they are the subject of the message, which briefs what is there inside the message. And it mentions the sender's name as well as the recipient's name, and finally, the date and the time as well are stated that explains exactly when the message was being received. And all this information is shown in the header of the message.

3 0
4 years ago
Other questions:
  • Which of the following applies to a DNS caching server? (Choose all that apply.)
    6·1 answer
  • Why might location be important when searching for a job?
    10·2 answers
  • A developer needs to create a visualforce page that displays case data. The page will be used by both support reps and support m
    10·1 answer
  • An exact-match query is:
    13·1 answer
  • XYZ Corp.’s facilities in Nashua, New Hampshire, are two office buildings 400 feet apart, each with its own LAN. To connect the
    9·1 answer
  • A field is _____. a complete entry in a database one of the categories in a database a group of twenty-seven records a cell in a
    8·1 answer
  • Q: If a program is invoked with "python program.py -r input.dat output.dat", what are the elements of argv?
    10·1 answer
  • Write a function called random_marks. random_marks should #take three parameters, all integers. It should return a #string. # #T
    13·1 answer
  • 1. Assuming you are downloading a 100MB (800Mb) file on a Network that can download data at 54Mbps.
    15·1 answer
  • What is the term for delivering an application over the internet called?
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!