Question

C programming

Write a C program to take a string as input and count and output number of small case letter, capital case letter and special characters in that string. Create function

KoitaCapital() to count number of capital case letters, function KoitaSmall() to count

number of small case letters and function KoitaSpecial() to count number of special

characters.

Sample Input:                   Sample Output:

Hello                                  Small case: 4,

                                           Capital case: 1,

                                           Special: 0


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

#include <stdio.h>

#include <string.h>

#define MAX 100 


int KoitaCapital(char s[])

{

   int l = strlen(s);

   int count = 0;

   for(int i = 0; i < l; i++)

      {

         if(s[i] >= 'A' && s[i] <= 'Z')

            {

               count ++;

            }

      }

   return count;

}


int KoitaSmall(char s[])

{

   int l = strlen(s);

   int count = 0;

   for(int i = 0; i < l; i++)

      {

         if(s[i] >= 'a' && s[i] <= 'z')

            {

               count ++;

            }

      }

   return count;

}


int KoitaSpecial(char s[])

{

   int l = strlen(s);

   int count = 0;

   for(int i = 0; i < l; i++)

      {

         if (!((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')))

            {

               count ++;

            }

      }

   return count;

}


int main()

{

   char str[MAX];

   printf("Enter a String : "); 

   scanf("%[^\n]s", str);    // taking a string input till a '\n' character

   

   printf("\nSmall case: %d", KoitaSmall(str));

   printf("\nCapital case: %d", KoitaCapital(str));

   printf("\nSpecial case: %d", KoitaSpecial(str));

   

   return 0;

}


answered by: Allen

> Thank you so much

Umar Ali Ashraf Thu, Jan 13, 2022 2:24 AM

Add a comment
Know the answer?
Add Answer to:
C programming
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
  • Write an LC-3 program (starting at memory location 0x3000) to take a string as input and...

    Write an LC-3 program (starting at memory location 0x3000) to take a string as input and then output information about this string. The end of the string will be denoted with the "#" character. Once the "#" has been found, output the following in order: 1) The letter “u” followed by the number of uppercase letters in the string (A-Z) 2) The letter “l” followed by the number of lowercase letters in the string (a-z) 3) The letter “n” followed...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • Question 2 (80 marks) This programming assignment is divided into two parts: (a) You will develop...

    Question 2 (80 marks) This programming assignment is divided into two parts: (a) You will develop a Java class called StringSummary based on the UML class diagram depicted in Figure 1 A user will enter a string of sentence (Figure 2), and your program will provide a summary of the sentence as shown in sample output Figure 3. The class contains several private attributes: • str stores the sentence input by user. • specialChars stores number of special characters (i.e....

  • ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of...

    ****C PROGRAMMING**** (100 points) Write a program that prompts the user to enter the name of a file. The program encoded sentences in the file and writes the encoded sentences to the output file. Enter the file name: messages.txt Output: encoded words are written to file: messages.txt.swt The program reads the content of the file and encodes a sentence by switching every alphabetical letter (lower case or upper case) with alphabetical position i, with the letter with alphabetical position 25...

  • Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt...

    Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a date is picked as December 18, 1946, then the 6 digits are 121846. Assume the dates are in the 20th century. To encrypt a message, you will shift each letter of the message by the number of spaces indicated by the corresponding digit. For example, to encrypt...

  • Please answer number 5 CS500 Programming Problems Create a subdirectory of your home directory named sep16...

    Please answer number 5 CS500 Programming Problems Create a subdirectory of your home directory named sep16 (note the case). Save your solutions in that directory in files named pl.c, p2.c, p3.c, p4. c, and p5. c. Your programs are due Friday September 16 at 4:00PM. You will not receive any credit if your programs are late, have the wrong filename, or are in the wrong directory. 1. Write a C program that reads stdin one character at a time and...

  • C++ Linux Compiler Letter Frequency Write a function that will take a string and return a...

    C++ Linux Compiler Letter Frequency Write a function that will take a string and return a count of each letter in the string. For example, "my dog ate my homework" contains 3 m's, 3 o's, 2 e's, 2 y's and one each of d, g, a, t, h, w, r and k. Your function should take a single string argument and return a dynamically allocated array of 26 integers representing the count of each of the letters a .. z...

  • Question 2 Write a program that will read in a line of text up to 100...

    Question 2 Write a program that will read in a line of text up to 100 characters as string, and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by whitespace, a period, a comma, or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespace, commas, an<d periods. When...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • Question / of 2. Case insensitive string compare: [40 marks/ Write a function that compares two...

    Question / of 2. Case insensitive string compare: [40 marks/ Write a function that compares two strings while ignoring the case of alphabetical characters. Your program will take two strings as input from the user and use your function to compare them. Assume a maximum C-string size of 1000 characters. Make sure your code works for any input number, not just the test cases. Your code will be tested on other test cases not listed here. Please properly comment your...

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