Enter a character string from the keyboard, and change the upper-case letters to lower-case letters, lower-case letters to upper-case letters, and output.

Source: Internet
Author: User

/* 2. programming questions
1) input a string from the keyboard, and change the upper-case letters to lower-case letters, lower-case letters to upper-case letters, and output.
[Requirement]
(1) Use a character array to store strings (the maximum value of a string is 100 ).
(2) Use the scanf function to input characters one by one and save them in the character array.
(3) Use the printf function to output characters in the character array one by one
*/

The question is simple, but the scanf function is required to input characters one by one and store them in the character array, which is difficult for beginners.

 

 # Include <stdio. h>
Void main ()
{
Int I = 0;
Char A [100], C;

Printf ("Enter the string content: \ t ");
Do {
Scanf ("% C", & A [I]);
C = A [I];
I ++;
} While (C! = '\ N ');

A [I] = '\ 0 ';

I = 0;
Printf ("input string content: \ t ");
While (A [I]! = '\ 0 ')
{
Printf ("% C", a [I]);
I ++;
}
Printf ("converted string content: \ t ");
I = 0;
While (A [I]! = '\ 0 ')
{
C = A [I];
If (C> = 'A' & C <= 'Z ')
A [I]-= 32;
Else if (C> = 'A' & C <= 'Z ')
A [I] + = 32;
Printf ("% C", a [I]);
I ++;
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.