Question

In C language This program reads in a series of words. All words consist of only...

In C language

This program reads in a series of words. All words consist of only lower-case letters ('a' through 'z'). None of the words entered will be longer than 50 letters. The program reads until ctrl-d (end-of-file), and then prints out all the lower-case letters that were missing in the input or a statement indicating the input has all the letters. Two executions of the program are shown below.

Enter your input:
the quick brown fox jumps over the lazy old dog
Your input contains all the letters
Enter your input:
alabama crimson tide
Missing letters: f g h j k p q u v w x y z

Hints:

  • Use an array of 26 elements to store the number of times you have seen the characters 'a' through 'z'. 'a' is actually an integer of value 97 (its ASCII value). If you subtract 'a' (or 97) from a lower-case letter, you will get a number in the range of 0 to 25.
  • To test this program, it is a good idea to create a file (input1.txt for example) to contain all the input words. Then test the program with input redirection: ./a.out < input1.txt (or ./a.exe < datafile). Make sure the input file ends with a newline.

LAB

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the following c program to find whether all the alphabets are in the string entered by the user.

Note: I have added screen shots and comments as needed inline.

Program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

//number of alphabets available
#define MAX 26

int main()
{
int ch1=1, ch2, i =0;
int alph[MAX];
char buf, buf1;
int flag= 0, firstChar=1;

memset(alph, 0, sizeof(alph));
printf("Enter your input:\n");

//read the character and update the aplh array
while ((read(0, &buf, sizeof(buf))) != 0)
{
ch1=buf;
//if its lower case letter and its new letter
//update the array's respective index
if( ch1 >= 97 && ch1 <= 122)
{
   int value = ch1 - 'a';
   if(alph[value]==0)
   {
       alph[value]=1;
   }
}
buf='\0';
fflush(stdin);
}

//print the missing letters
printf("\n");
for(i=0; i<MAX; i++)
{
if(alph[i] == 0)
{
   if (flag == 0)
   {
       printf("Missing letters: ");
       flag = 1;
   }
     
   printf(" %c", 'a' + i);
}
}

//if all letter are present in the array, then print
//following message
if (flag == 0)
{
printf("Your input contains all the letters\n");
}
else
{
printf("\n");
}

return 0;
}

Output:

osboxes@osboxes:~/Chegg/C$ ./a.out
Enter your input:
asdf
Missing letters: b c e g h i j k l m n o p q r t u v w x y z
osboxes@osboxes:~/Chegg/C$ ./a.out <text
Enter your input:

Missing letters: e f g h i j k l m n o p q r s t u v w x y z
osboxes@osboxes:~/Chegg/C$ ./a.out
Enter your input:
the quick brown fox jumps over the lazy old dog
Your input contains all the letters
osboxes@osboxes:~/Chegg/C$

Screen Shot:

Text file containing the input:

Add a comment
Know the answer?
Add Answer to:
In C language This program reads in a series of words. All words consist of only...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programming (not c++) This programs input is a series of words. All words consist of...

    C programming (not c++) This programs input is a series of words. All words consist of only lowercase letters(a-z), no uppercase letters or digits or punctuation or other special symbols. The program reads until end-of-file, and then prints out the lowercase letters that were not seen in the input. Enter your input: the quick brown fox jumps over the lazy old dog Missing letters: enter your input: roll tide missing letters: a b c f g h j k m...

  • I/O program for C Write a program in direct1.c which reads from standard input a line...

    I/O program for C Write a program in direct1.c which reads from standard input a line and then outputs that line immediately to standard output. it should read the first line only ! Then, write another program called direct2.c which reads from standard input every line until end of input and outputs them to standard output. Everything that goes in should come out exactly as it was. Compile both programs and run them on the input files given below The...

  • Help please Write a program named one.c that takes a single command-line argument, the name of...

    Help please Write a program named one.c that takes a single command-line argument, the name of a file. Your program should read all the strings (tokens) from this file and write all the strings that are potentially legal words (the string contains only upper-case and lower-case characters in any combination) to the file words. Your program should ignore everything else (do not write those strings anywhere 1. As an example, running /a.out dsia would result in the generation of the...

  • c language with comments please! Name this program one.c- This program reads integers from standard input...

    c language with comments please! Name this program one.c- This program reads integers from standard input until end-of-file (control-d) and writes them to either the file good or the file bad. Write the first number to the file good. After that, as long as the number is larger than the one it read before (the previous value, write that number to the file good. Otherwise, write that number to the file bad. Two sample executions are shown below good bad...

  • Write a C program that reads characters from a text file, and recognizes the identifiers in...

    Write a C program that reads characters from a text file, and recognizes the identifiers in the text file. It ignores the rest of the characters. An identifier is a sequence of letters, digits, and underscore characters, where the first character is always a letter or an underscore character. Lower and upper case characters can be part of the identifier. The recognized identifier are copied into the output text. b. Change the C program in exercise 2, so that all...

  • Write a Java program that reads words from a text file and displays all the non-duplicate...

    Write a Java program that reads words from a text file and displays all the non-duplicate words in ascending order. The text file is passed as a command-line argument. Command line argument: test2001.txt Correct output: Words in ascending order... 1mango Salami apple banana boat zebra

  • 1. Write a python program that reads a file and prints the letters in increasing order...

    1. Write a python program that reads a file and prints the letters in increasing order of frequency. Your program should convert entire input to lower case and only counts letters a-z. Special characters or spaces should not be counted. Each letter and it's occurrences should be listed on a separate line. 2. Test and verify your program and it's output. ---Please provide a code and a screenshot of the code and output. Thank you. ----

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line...

    Write a C++ program that repeatedly reads lines until an EOF is encountered. As each line is read, the program strips out all characters that are not upper or lower case letters or spaces, and then outputs the line. Thus, the program acts as a filter and issues no prompt. There are many ways this program could be written, but to receive full credit, you must observe the following: Place your code in a file called filterChars.cpp. The program should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT