ZeroDamage August 10, 2008 Share ZeroDamage Member August 10, 2008 Question for you programming gurus out there. I need to write a program that does the following: Inputs a line of text with function gets into char array s[100]. The line must output in both uppercase and lowercase. This has to be a "C" program. Anyone understand what this is asking and can maybe throw up an example? Thanks in advance. Link to comment Share on other sites More sharing options...
mookie August 10, 2008 Share mookie GC Alumni August 10, 2008 I don't know how close this is because I never write C (only C++), but it should be close. char s[100]; gets(s); for(int u = 0; s[u]; s++) print((char)((s[u] <= 'z' && s[u] >= 'a') ? (s[u] + 'A' - 'a'): (s[u]))); print('\n'); for(int l = 0; s[l]; s++) print((char)((s[u] <= 'Z' && s[u] >= 'A') ? (s[u] + 'a' - 'A'): (s[u]))); print('\n'); Link to comment Share on other sites More sharing options...
ZeroDamage August 10, 2008 Author Share ZeroDamage Member August 10, 2008 Wow, thanks Mookie. That looks right. Anyone care to confirm or deny? Link to comment Share on other sites More sharing options...
ZeroDamage August 10, 2008 Author Share ZeroDamage Member August 10, 2008 This actually looks a bit more like what C should be I think. Thoughts? #include <stdio.h> int main() { char s[100]; gets(s); for(int u = 0; s[u]; s++) { printf((char)((s[u] <= 'z' && s[u] >= 'a') ? (s[u] + 'A' - 'a'): (s[u]))); printf('\n'); } for(int l = 0; s[l]; s++) { printf((char)((s[u] <= 'Z' && s[u] >= 'A') ? (s[u] + 'a' - 'A'): (s[u]))); printf('\n'); } return 0; } Link to comment Share on other sites More sharing options...
mookie August 10, 2008 Share mookie GC Alumni August 10, 2008 You have a problem that that's going to print each character on its own line. Link to comment Share on other sites More sharing options...
NOFX August 11, 2008 Share NOFX Member August 11, 2008 (edited) see below Edited August 11, 2008 by NOFX Link to comment Share on other sites More sharing options...
LoveForPriscillaChan August 11, 2008 Share LoveForPriscillaChan Member August 11, 2008 (edited) are you constricted to C? do you have to use "gets" Edited August 15, 2008 by LoveForPriscillaChan Link to comment Share on other sites More sharing options...
NOFX August 11, 2008 Share NOFX Member August 11, 2008 (edited) int main(){ char s[100]; int x=0; std::gets(s); while(s[x] != '\ 0') { printf("%c", toupper(s[x])); x++; } printf("%c", '\n'); x=0; while(s[x] != '\ 0') { printf("%c", tolower(s[x])); x++; } } don't forget to include <cctype> Take out a the spacing in \ 0, forums won't print '' Edited August 11, 2008 by NOFX Link to comment Share on other sites More sharing options...
ZeroDamage August 11, 2008 Author Share ZeroDamage Member August 11, 2008 Thanks fellas. I was on a tight deadline and yes, it had to be C. NOFX is a programming ninja so I went with his. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now