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
Algorithm to print the first 10 odd numbers​
77julia77 [94]

Answer:

I have the code written in c++ but the logic will be the same you just have to change the syntax ( if you're writing different language)

Explanation:

please mark brainliest

4 0
2 years ago
Which key toggles between insert mode and overtype mode?
andrew-mc [135]
The keyboard key that toggles between insert mode and overtype mode is the INSERT key.
7 0
3 years ago
You areYou are a member of the application development organization for a small but rapidly growing software company that produc
bija089 [108]

Answer:

Following are the solution to this question:

Explanation:

Please find the complete question in the attached file.

It will obtain as much information about this matter as necessary even before the conference. It includes its gravity or probability of risk, various cases in the entire event, the possible solutions to the issues, as well as the consequences for parties involved in each potential answer, and Only at conferences, it may clarify to my boss that the explanation for the problem and also in details. It will be doing everything possible and try not to conceal the details but highlight the problem.

3 0
3 years ago
Describe the two alternative for specifying structural constraints on relationships types?
AysviL [449]

Answer:

They are the cardinality ratio and participation constraints.

Explanation:

The Cardinality Ratio: This is for the binary relationship that specifies the max number of instances of relationships in which an entry can take part in. As an example, the Student Of binary relationship form, School: Student, the cardinality ratio of this is 1: N. and that means each of the schools can be mapped to any number of students, however, one student can be mapped to only one school. And various possible cardinality ratios for various types of binary relationships can be 1: N, N:1, 1:1, and M: N.

Participation constraint: This stipulates that an entity being be contingent upon another entity through relationship form. And it stipulates the least figure of instances of relationship which each of the entity can indulge in, and is often termed as least cardinality constraint. And we have participation types: partial and total.

4 0
3 years ago
Users with micrsoft account have access to an online storage and sharing system known as?
sweet [91]
The answer would be Onedrive!

:) Hope this helps out.
3 0
4 years ago
Other questions:
  • What is the base for a hexadecimal number system?
    11·1 answer
  • Assume that passwords are selected from four-character combinations of 26 alphabeticcharacters. Assume that an adversary is able
    11·1 answer
  • There are two main advantages to using multiple threads in a process: 1) Less work involved in creating a new thread rather than
    7·1 answer
  • How are logical operators used?
    14·1 answer
  • Compute (110110001.01)2 + (27.12)10 + (121.25)16 – (130.20)16 and display the answer in hexadecimal base.
    7·1 answer
  • ______ is/are the replacement of human operation and control of machinery with some form of programmed control.
    11·1 answer
  • What are Layers in computer class 7. no scams please​
    9·2 answers
  • In this screenshot, the circled item is the
    15·2 answers
  • What does CPU stand for
    7·1 answer
  • Suppose you are asked to design a rotating disk where the number of bits per track is constant. You know that the number of bits
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!