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
pantera1 [17]
3 years ago
13

Write a C program that counts the number of vowels in a word. The C program reads words from an input file and then stores in an

output file the word and its number of vowels. At the end it also stores the word with the most and the word with the fewest vowels. Extra bonus: Your program should handle the situation in which there are several words with the maximum and minimum number of vowels.
Computers and Technology
1 answer:
polet [3.4K]3 years ago
5 0

Answer:

Explanation:

The following code is written in C and does what the question requires. It uses the input file reads it and outputs the number of vowels to the file called output.dat

#include <ctype.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

int str_count_in_chars(char *start, char *end, char *chars) {

   int count = 0;

   for (; start != end; count += !!strchr(chars, *(start++)));

   return count;

}

void str_swap_in_chars(size_t str_len, char **str, char *chars) {

   for (int front = 0, back = str_len - 1; front < back; front++) {

       if (strchr(chars, (*str)[front])) {

           for (; !strchr(chars, (*str)[back]); back--);

           char tmp = (*str)[front];

           (*str)[front] = (*str)[back];

           (*str)[back--] = tmp;

       }

   }

}

char *file_to_str(FILE *fin) {

   int buf_len = 64;

   char buf[buf_len];

   char *str = malloc(buf_len);

   str[0] = '\0';

   for (int i = 1; fgets(buf, buf_len, fin); i++) {

       if (!(str = realloc(str, i * buf_len))) {

           fprintf(stderr, "%s:%d realloc failed\n", __FILE__, __LINE__);

           exit(1);

       }

       strcat(str, buf);

   }

   return str;

}

int main() {

   char *vowels = "aeiou";

   FILE *fin = fopen("input.dat", "r");

   FILE *fout = fopen("output.dat", "w");

   if (!fin || !fout) {

       fprintf(stderr, "%s:%d fopen failed\n", __FILE__, __LINE__);

       exit(1);

   }

   char *words = file_to_str(fin);

   fclose(fin);

   int words_len = strlen(words);

   for (int i = 0; i < words_len;) {

       if (isspace(words[i])) {

           fputc(words[i++], fout);

           continue;

       }

       int start = i;

       for (; i < words_len && !isspace(words[i]); i++);

       char *word = words + start;

       int word_len = i - start;

       int vowel_count = str_count_in_chars(word, words + i, vowels);

       if (vowel_count % 2 == 0) {

           str_swap_in_chars(word_len, &word, vowels);

       }

       fprintf(fout, "%.*s_%dvow", word_len, word, vowel_count);

   }

   fclose(fout);  

   free(words);

   return 0;

}

You might be interested in
A single line text input control with an initial value as +971
Nezavi [6.7K]

Answer:

What's about this initial value equal to 971

Explanation:

\sqrt{2}

8 0
3 years ago
If you're writing a timeline of a historical. What type of graphic organizer would you most likely choose to use in your rerouti
Tom [10]
I would use excel for a line graph.
8 0
3 years ago
2) A ________ uses electronic memory and has no motors or moving parts. A) mechanical hard drive B) solid-state drive C) Blu-ray
grin007 [14]

Answer:

A.mechanical hard

Explanation:

brainliest me and follow ty

7 0
3 years ago
Suppose Client X initiates a FTP session with Server W and requests data transferring. At about the same time, Client Y also ini
sergeinik [125]

Answer:

Folllows are the solution to the given points:

Explanation:

In this question, the server uses special port 21 and  20 for the command and data transfer. A customer uses a random short-term N > 1023 and N+1 ports Listen and the Ports may be randomly distributed and the following samples are given for:  

In point (a):

X: 1030 Client, W server: 21 (service)  

W: 20 server (data) ,Client X:1031

In point (b):

Server W: 21 (command) Client Y: 1035  

Client Y: 1036, (data) Server W: 20  

In point (c):

Client X: 1030, Server W: 21.  

Client X: 1031, (data) Server W: 20  

In point (d):

Client X: 1035, Server W: 21.  

Client X: 1036 ,(data): Server W: 20.  

In point (e):

Yes, it's an opportunity. It can be the same as a certain likelihood.  

In point (f):

The port of the server is the norm. If W and Y are on the same host, the client's port numbers can vary.  

4 0
4 years ago
A data dictionary is also known as ________. Group of answer choices a data warehouse clickstream data a data mart ubiquitous co
Marizza181 [45]

Answer:

A data dictionary is also known as metadata repository.

8 0
3 years ago
Other questions:
  • Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006.Given a variable modelYear write a statem
    5·1 answer
  • How many hours did it take supercomputer to calculate pi?
    6·1 answer
  • Which risk management framework does the organization of standardization publish
    13·1 answer
  • Consider the following two tables where EmployeeNum is primary key in both tables. What is the result of combining the two table
    5·1 answer
  • an IPv6 packet has a 40 byte base header, a 20 byte destination options extension header (which is not used for routing) and 200
    5·1 answer
  • In classical conditioning, _____ means that the CS and US are presented closely together, whereas _____ means that the CS is a g
    6·1 answer
  • Why is Data-Driven Analytics of interest to companies?
    12·1 answer
  • How many passes will it take to find the four in this list?
    12·2 answers
  • What data type would best hold the numeric value?
    8·1 answer
  • Distributed databases and data warehouses would be considered which data model type?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!