![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
|
Hi just wondering if anyone has any code that changes a uppercase letter to lowercase and visa versa...
I've declared 2 arrays and an alpha above all my functions that are char lower[] = **'a','b','c'...rest letters..'z'} char Upper[] = **'A','B','C'...rest letters...'Z'} Int alpha The code I got so far for the functions (toLower & toUpper) is char toLowerCase(char c) for(int i=0; lower!='\0'; i++) ** If(c==lower) ** (Maybe more code here?) return lower; } else return false; }//end for }//end function char toUpperCase(char c) ** for(int i=0; lower!='\0'; i++) ** If(c==upper) ** (Maybe more code here?) return true; } else return false; }//end for }//end function I don't know what other code to put in there to make it change to uppercase |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Registered User
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2
|
Re: C++ help
Here's what I came up with (for some reason, the brackets turn to ** on the forum, so take that into account):
Code:
#include <stdio.h>
/* Alphabet arrays */
char upperChars[26] = **'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char lowerChars[26] = **'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
/* Characters through the various stages */
char currentChar, newChar, changed;
/* Declare the function to be used below */
char convertChar(char);
int main()**
while(TRUE)** /* Keep this going on and on until the user quits */
printf("Enter a character: ");
scanf("%c", ¤tChar); /* Get the user's input */
newChar = convertChar(currentChar); /* Runs the conversion function below */
printf("Opposite case is is: %c\n", newChar); /* Printf the results */
}
return 0;
}
/* The conversion function */
char convertChar(char toBeChanged)**
for(int i=0; i<26; i++)** /* Loop through all the letters of the alphabet */
if(toBeChanged == upperChars[i])** /* If the user's char is equal to the letter we're on in the for loop... */
changed = lowerChars[i]; /* set it equal to the char in the same position in the opposite array */
}
else if(toBeChanged == lowerChars[i])**
changed = upperChars[i];
}
}
return changed;
}
|
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Nov 2007
Posts: 388
OS: Mac OS X 10.5.7 and XP SP2
|
Re: C++ help
Sorry, I just tested that now and I got 2 errors...
1) Declare int i outside the for loop 2) while(TRUE) is incorrect, set a boolean variable equal to true and use that, if you want the program to keep looping. Here it is with the changes in place: Code:
#include <stdio.h>
/* Alphabet arrays */
char upperChars[26] = **'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char lowerChars[26] = **'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
/* Characters through the various stages */
char currentChar, newChar, changed;
/* Declare the function to be used below */
char convertChar(char);
/* Declare the loop bool */
int loop = 1;
int main()**
while(loop)** /* Keep this going on and on until the user quits */
printf("Enter a character: ");
scanf("%c", ¤tChar); /* Get the user's input */
newChar = convertChar(currentChar); /* Runs the conversion function below */
printf("Opposite case is is: %c\n", newChar); /* Printf the results */
}
return 0;
}
/* The conversion function */
char convertChar(char toBeChanged)**
int i;
for(i=0; i<26; i++)** /* Loop through all the letters of the alphabet */
if(toBeChanged == upperChars[i])** /* If the user's char is equal to the letter we're on in the for loop... */
changed = lowerChars[i]; /* set it equal to the char in the same position in the opposite array */
}
else if(toBeChanged == lowerChars[i])**
changed = upperChars[i];
}
}
return changed;
}
Last edited by FredT; 05-08-2009 at 05:53 PM. |
|
|
|
![]() |
| Thread Tools | |
|
|