Kevin321888999

Lab 5 part A

Apr 25th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <ctype.h>//Standard library for Characters.
  4.  
  5. void banner(void){ //Function to print out name and class
  6.   printf("------------------------\n");
  7.   printf("Malachi Sor\nCSCI 1110-01\n");
  8.   printf("--------------------------\n");
  9. }
  10.  
  11. int main(void) {
  12.  
  13.   banner();
  14.   int counter =0;//counter will start at 0
  15.   while(1){ //This will check if the character is true because 1 means true.
  16.     char character;  
  17.  
  18.    printf("\nEnter the character: ");
  19.     for(;;){
  20.        //Don't put the printf statment under the for loop or else it will Loop and input every single character you have put even though it is not S.
  21.       scanf("%c",&character);//user input the phrase or word.
  22.       if (character=='s'){//This will check if the user input is a lower case 's'.
  23.         counter ++; //increment the counter by 1
  24.         printf("th");
  25.       }
  26.       else if (character=='S'){// will check if the user input has the character 'S' as a capital.
  27.         counter ++;//increments by 1
  28.         printf("Th");
  29.       }
  30.       else { //If there are no S, then the word will just print itself out.
  31.         printf("%c",character);
  32.         counter++;
  33.       }
  34.       if (character=='.'){//checks if the user input has the period signifying the end of the loop and leading to the break.
  35.         break;}// breaks out of the for loop into the while loop.
  36.     }break;}//breaks out of the while loop and goes to the return 0.
  37.   return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment