Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* CS261- Assignment 1 - Q5.c
- * Sean McGlothlin
- * 10/4/12
- * Solution description:
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define LENGTH 20
- /*converts ch to upper case, assuming it is in lower case currently*/
- char toUpperCase(char ch){
- return ch-'a'+'A';
- }
- /*converts ch to lower case, assuming it is in upper case currently*/
- char toLowerCase(char ch){
- return ch-'A'+'a';
- }
- void sticky(char *word){
- int testLower = 0;
- int testUpper = 0;
- for(int i = 0; i < LENGTH; i++) {
- if(i % 2 == 1) {
- testLower = atoi(word[i]);
- if(testLower > 64 && testLower < 91) { // ASCII values for upper case letters
- word[i] = toLowerCase(word[i]);
- }
- }
- if(i % 2 == 0) {
- testUpper = atoi(word[i]);
- if(testUpper > 96 && testUpper < 123) { // ASCII values for lower case letters
- word[i] = toUpperCase(word[i]);
- }
- }
- }
- /*Convert to sticky caps*/
- }
- int main(){
- char word[LENGTH];
- printf("Enter a word (max 20 chars): \n");
- scanf("%s", &word);
- sticky(word);
- printf("%s\n", word);
- return 0;
- }
Add Comment
Please, Sign In to add comment