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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 05-06-2009, 10:09 AM   #1 (permalink)
Registered User
 
Join Date: Apr 2009
Location: Australia
Posts: 2
OS: Windows Vista


Send a message via MSN to LivDawg Send a message via Yahoo to LivDawg
Idea C++ help

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
LivDawg is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 05-08-2009, 05:37 PM   #2 (permalink)
Registered User
 
FredT's Avatar
 
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", &currentChar); /* 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;
}
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 05-08-2009, 05:41 PM   #3 (permalink)
Registered User
 
FredT's Avatar
 
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", &currentChar); /* 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.
FredT is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 11:48 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85