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(n ____ enables a database administrator to define schema components.
zzz [600]
Ig a(n) network cuz the database management language uses a schema and subschema data definition language; the schema data definition language enables database administrators to define schema components, and the subschema data definition language allows the application programs to define database components that will be used.

hope this helps u out. :)
8 0
2 years ago
When using a function to preform a calculation how would you select the range of numbers to use
Ivan

Answer:

<u>Returns the average  (arithmetic mean) of the arguments.</u>

Explanation:

For example, if the range A1:A20 contains numbers, the formula =AVERAGE(A1:A20) returns the average of those numbers.

<u><em>(I hope this helps!)</em></u>

7 0
2 years ago
Why did Herman Hollerith invent the Tabulating Machine?
Anvisha [2.4K]

Answer:

the machine was developed to help process data for the 1890 U.S. Census.

Explanation:

U.U

8 0
3 years ago
2.3.4 CodeHS HTML Word Definitions
Kipish [7]

Answer:

Aplolgies, your question is not formated correctly, please edit and I will answer it though the comment, thanks!

3 0
2 years ago
Hit and Slopes Program: A Write a program that can be used by a ski resort to keep track if local snow conditions for one week.
Llana [10]

Answer:

The java program is as follows.  

import java.lang.*;  

import java.util.Scanner;  

public class Main  

{  

//array declaration  

static int weekdays=7;  

static int[] snowfall_inch = new int[weekdays];  

static String[] snowfall_date = new String[weekdays];  

//variables to store average and maximum  

static double avg;  

static int max;  

public static void main(String[] args) {  

Scanner sc = new Scanner(System.in);  

System.out.print("Enter the month: ");  

String month = sc.next();  

for(int n=0; n<weekdays; n++)  

{  

System.out.print("\nEnter the date for day "+(n+1)+ ": ");  

snowfall_date[n] = sc.next();  

System.out.print("Enter the inches of snowfall for day "+(n+1) +": ");  

snowfall_inch[n] = sc.nextInt();  

avg = avg + snowfall_inch[n];  

}  

avg = avg/weekdays;  

System.out.printf("The average snowfall for the week is %.4f",avg);  

for(int n=0; n<weekdays-1; n++)  

{  

if(snowfall_inch[n] < snowfall_inch[n+1])  

max=snowfall_inch[n+1];  

}  

System.out.println("\nThe maximum snowfall for the week is "+max);  

}  

}  

OUTPUT  

Enter the date for day 2: 12-2-2019

Enter the inches of snowfall for day 2: 23  

Enter the date for day 3: 12-3-2019

Enter the inches of snowfall for day 3: 13  

Enter the date for day 4: 12-4-2019

Enter the inches of snowfall for day 4: 14  

Enter the date for day 5: 12-5-2019

Enter the inches of snowfall for day 5: 34  

Enter the date for day 6: 12-6-2019

Enter the inches of snowfall for day 6: 34  

Enter the date for day 7: 12-7-2019

Enter the inches of snowfall for day 7: 22

The average snowfall for the week is 21.7143  

The maximum snowfall for the week is 34  

Explanation:

1. Two arrays are declared to store dates and snowfall inches with string and integer datatypes respectively.  

2. Variables are declared to store maximum and average snowfall values with integer and double datatypes respectively.  

3. User input is taken for the month, and the dates and snowfall inch values for a week. The input is taken in for loop.  

4. Next, for loop is used to find the average and maximum snowfall of the week.  

5. These values are displayed to the user as shown in the output.

5 0
3 years ago
Other questions:
  • Consider this scenario: A major government agency experiences a data breach. As a result, more than 100,000 personal records are
    7·2 answers
  • What do radio telescopes use to gather and focus radio waves?
    14·2 answers
  • What is an effective way to assess user requests for additional features and functions
    10·1 answer
  • Are headphones considered a computer? Why or why not?
    13·2 answers
  • Operational feasibility, which refers to user acceptance and support, as well as management acceptance and support, is also know
    9·1 answer
  • Which is said to be ‘computer on a chip’ (a) Micro processors (b) Microcontrollers (c) Both (c) None of the above
    9·1 answer
  • Consider the following code segment
    15·1 answer
  • Several small stores rent space within a larger shopping centre. The owners of the shopping centre have provided a physical netw
    15·1 answer
  • Which is government departments fund the Global Positioning System
    6·1 answer
  • Someone put malware on your computer that records all of your keystrokes. what aspect of security was primarily attacked? choose
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!