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
Please help me with this!
Aleksandr [31]

def zipZapZop():

   number = int(input("Enter the number: "))

   dictionary = {3: "zip", 5: "zap", 7: "zop"}

   amount = 0<em> #amount of non-divisible numbers by 3, 5 and 7</em>

<em>    for key, value in dictionary.items():</em>

       if(number%key == 0): <em>#key is the number</em>

           print(value) <em>#value can be or zip, or zap, or zop</em>

       else: amount += 1 #the number of "amount" increases every time, when the number is not divisible by 3, or 5, or 7

   if(amount == 3): print(number)    <em>#if the number is not by any of them, then we should print the number</em>

zipZapZop()

4 0
3 years ago
When do I use while loops
Marat540 [252]

Answer:

When you dont know how long the loop is going to run for

Explanation:

7 0
3 years ago
Two technicians are discussing using a lift to raise a vehicle. Technician A says to be sure the lift pads on the lift are conta
lianna [129]
Its B no doubt
cuz ik how to do this i took classes for this so ik im right ight
6 0
3 years ago
Read 2 more answers
A technician is troubleshooting an employee laptop that has a wired network connectivity issue. The laptop can connect to the in
defon

By Tx/Rx reverse the technician can address this issue.

C. Tx/Rx reverse

<u>Explanation:</u>

Technician has to trouble the laptop, since the laptop is connected and got internet while is the network resources inside the office. But if he connects the same laptop in research lab end user is not connected

Following troubleshooting to made

1. Routing is done properly

2. Any packet dropping by using TRACE command in windows operating system.

Since DHCP is used in office, whereas same type is not used in research lab. End user can try TX/RX reverse cable to connect in the research laptop.

5 0
4 years ago
Why must web designers select a common font?
Mnenie [13.5K]

Web designers select a common font To make the page easier to read

<u>Explanation:</u>

The taste and preferences of one person differs greatly with that of the other person. Some person likes one type of font in web design that appeals his eyes whereas it may be irritating to others. While designing a web page some of the important things must be taken into consideration in which the font type that you use is an important thing. .

Web pages usually have limited font types that you can use with. A wed design that is designed greatly with pleasing layouts and designs, visual cues, variations in order to ease the readers gains more visitors. The reason for which the web designers commonly select a standard font is to provide readers an easier way to read the website's contents.

3 0
4 years ago
Read 2 more answers
Other questions:
  • Assign a pointer to any instance of searchChar in personName to searchResult.#include #include using namespace std;int main() {c
    5·1 answer
  • __________ is an attempt to gain access to a network by posing as an authorized user in order to find sensitive information, suc
    5·1 answer
  • Which of the following statements will ivoke the function get_course and store the reutrn values correctly? A. get_course(course
    8·1 answer
  • Which of the following illustrates an example of a Boolean data type?
    9·1 answer
  • printArray is a function that has two parameters. The first parameter is an array of element type int and the second is an int,
    10·1 answer
  • Social media is an effective form of e-commerce. True False
    12·1 answer
  • What is text formatting/
    5·1 answer
  • Help fast pleas. 3. How is this text formatted? (1 point)
    14·1 answer
  • Mi amiga es una chica y es soltera y quiere novia, a cualquiera le interesa?
    11·1 answer
  • A major hospital uses an agile approach to manage surgery schedules. a large board set up in a common office allows staff to qui
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!