Jump to content

Programming Help


ZeroDamage

Recommended Posts

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

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

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

Member
(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 by NOFX
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...