Guest User

Untitled

a guest
Dec 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. /* CS261- Assignment 1 - Q5.c
  2.  * Sean McGlothlin
  3.  * 10/4/12
  4.  * Solution description:
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. #define LENGTH 20
  12.  
  13. /*converts ch to upper case, assuming it is in lower case currently*/
  14. char toUpperCase(char ch){
  15.      return ch-'a'+'A';
  16. }
  17.  
  18.  
  19. /*converts ch to lower case, assuming it is in upper case currently*/
  20. char toLowerCase(char ch){
  21.      return ch-'A'+'a';
  22. }
  23.  
  24.  
  25. void sticky(char *word){
  26.  
  27.     int testLower = 0;
  28.     int testUpper = 0;
  29.  
  30.     for(int i = 0; i < LENGTH; i++) {
  31.  
  32.         if(i % 2 == 1) {
  33.             testLower = atoi(word[i]);
  34.             if(testLower > 64 && testLower < 91) {   // ASCII values for upper case letters
  35.                 word[i] = toLowerCase(word[i]);
  36.             }
  37.         }
  38.         if(i % 2 == 0) {
  39.             testUpper = atoi(word[i]);
  40.             if(testUpper > 96 && testUpper < 123) {  // ASCII values for lower case letters
  41.                 word[i] = toUpperCase(word[i]);
  42.             }
  43.         }
  44.     }
  45.      /*Convert to sticky caps*/
  46. }
  47.  
  48.  
  49. int main(){
  50.  
  51.     char word[LENGTH];
  52.  
  53.     printf("Enter a word (max 20 chars): \n");
  54.     scanf("%s", &word);
  55.  
  56.     sticky(word);
  57.  
  58.     printf("%s\n", word);
  59.  
  60.     return 0;
  61. }
Add Comment
Please, Sign In to add comment