Advertisement
dinophanhk

[C] Get number of 'a', 'i', 'u', 'e', 'o' in string

Jun 18th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.49 KB | None | 0 0
  1. //Code programming that I write in Xcode on OSX, some programming tools on Windows will be incompatible.
  2. //Please read instructions on how to edit specific.
  3.  
  4. #include "stdio.h"
  5. #include "string.h"
  6.  
  7. int main(void) {
  8.     char cString[31];
  9.     int i, numberOfA = 0, numberOfI = 0, numberOfU = 0, numberOfE = 0, numberOfO = 0;
  10.     printf("Enter string (up to 30): ");
  11.     gets(cString);
  12.    
  13.     int numberOfElement = (int) strlen(cString) - 1;
  14.    
  15.    
  16.     for (i = 0; i < numberOfElement; i++) {
  17.         if (cString[i] == 'i' || cString[i] == 'I') {
  18.             numberOfI++;
  19.         }
  20.     }
  21.    
  22.     for (i = 0; i < numberOfElement; i++) {
  23.         if (cString[i] == 'a' || cString[i] == 'A') {
  24.             numberOfA++;
  25.         }
  26.     }
  27.    
  28.     for (i = 0; i < numberOfElement; i++) {
  29.         if (cString[i] == 'u' || cString[i] == 'U') {
  30.             numberOfU++;
  31.         }
  32.     }
  33.    
  34.     for (i = 0; i < numberOfElement; i++) {
  35.         if (cString[i] == 'e' || cString[i] == 'E') {
  36.             numberOfE++;
  37.         }
  38.     }
  39.    
  40.     for (i = 0; i < numberOfElement; i++) {
  41.         if (cString[i] == 'o' || cString[i] == 'O') {
  42.             numberOfO++;
  43.         }
  44.     }
  45.    
  46.     printf("Char(s) have 'A' or 'a': %d\n", numberOfA);
  47.     printf("Char(s) have 'I' or 'i': %d\n", numberOfI);
  48.     printf("Char(s) have 'U' or 'u': %d\n", numberOfU);
  49.     printf("Char(s) have 'E' or 'e': %d\n", numberOfE);
  50.     printf("Char(s) have 'O' or 'o': %d\n", numberOfO);
  51.    
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement