C Program to Find Total of Even Integers

C Program for Testing, Reading and Writing Character Type

In the following post we can give example of C Program for Testing, Reading and Writing Character with step by step. The below code example shows the use of getchar function in an interactive environment. The program displays a question of YES/NO type to the user and reads the user’s response in a single character (Y or N). If the response is Y, it outputs the message

Example,

My name is Yaso

otherwise, outputs.


You are good for nothing

Note there is one line space between the input text and output message.

C Program for Reading Character from Keyboard Example

#include <stdio.h>
main()
{
char answer;
printf("Would you like to know my name?\n");
printf("Type Y for YES and N for NO: ");
answer = getchar(); /* .... Reading a character...*/
if(answer == 'Y' || answer == 'y')
printf("\n\nMy name is Yasp\n");
else
printf("\n\nYou are good for nothing\n");
}

Output display as per below,

Would you like to know my name?
Type Y for YES and N for NO: Y
My name is Yaso

Would you like to know my name?
Type Y for YES and N for NO: n
You are good for nothing

C Program for Testing Character Type with Example

This C Program requests the user to enter a character and displays a message on the screen telling the user whether the character is an alphabet or digit, or any other special character.

This program receives a character from the keyboard and tests whether it is a letter or digit and prints out a message accordingly. These tests are done with the help of the following functions:

  • isalpha(character)
  • isdigit(character)

For example, isalpha assumes a value non-zero (TRUE) if the argument character contains an alphabet; otherwise it assumes 0 (FALSE). Similar is the case with the function isdigit.

#include <stdio.h>
#include <ctype.h>
main()
{
char character;
printf("Press any key\n");
character = getchar();
if (isalpha(character) > 0)
printf("The character is a letter.");
else
if (isdigit (character) > 0)
printf("The character is a digit.");
else
printf("The character is not alphanumeric.");
}

Output Display as below,

Press any key
h
The character is a letter.
Press any key
5
The character is a digit.
Press any key
*
The character is not alphanumeric.

C Program for Writing Character To the Screen with Example

This C Program that reads a character from keyboard and then prints it in reverse case is given in below example. That is, if the input is upper case, the output will be lower case and vice versa.

The program uses three new functions: islower, toupper, and tolower. The function islower is a conditional function and takes the value TRUE if the argument is a lower case alphabet; otherwise takes the value FALSE. The function toupper converts the lower case argument into an upper case alphabet while the function tolower does the reverse.

#include <stdio.h>
#include <ctype.h>
main()
{
char alphabet;
printf("Enter an alphabet");
putchar('\n'); /* move to next line */
alphabet = getchar();
if (islower(alphabet))
putchar(toupper(alphabet));
else
putchar(tolower(alphabet));
}

Output Display as below,

Enter an alphabet
a
A
Enter an alphabet
Q
q
Enter an alphabet
z
Z

Let me know if you find any difficulty in understanding this C Program for Testing, Reading and Writing Character with example and I would be glad to explain it further.

Online Training Tutorials

  • Creating Material MasterHow to Maintain default User Settings when Creating Material Master?Creating Material Master: Where in the config can you default the Industry sector in MM01? You can define that a particular industry sector is proposed whenever the user creates a […]
  • SAP MM interview questionsWhat is SAP Vendor Evaluation System and how Integrated?The vendor Evaluation component has been completely integrated into SAP MM Purchasing. The information such as delivery dates, prices, and quantities can be taken from purchase orders. The […]
  • cost center accountingSAP Cost Center Accounting – OverviewSAP Cost center Accounting are used to track where cost occur in the organization. As costs are incurred, they are assigned or posted to the appropriate cost center. The posting and […]
  • SAP NetWeaverWhat is SAP NetWeaver?SAP NetWeaver, the next evolution of mySAP Technology integrates information and business processes across technologies and organizations. What's more, SAP NetWeaver embraces Internet […]
  • SAP SystemHigh Level & Fundamental understandings of SAP System ArchitectureIt is an undeniable fact that SAP gains more and more customers such as big US and global Corporations and government. SAP’s greatest opportunity probably lies beyond Microsoft or IBM […]
  • C Program to Find Total of Even IntegersC Program to Find Greatest of Three NumbersIn this tutorial, we have shared a program that compares Program to find greatest of 3 numbers. The main objective is to study about decision statements such as’ if else’ statement that […]
  • SAP Sapphire 2018SAP Sapphire 2018 ASUG Annual ConferenceSAP Sapphire 2018 conference is, by all means, the most significant event so far. Over 100 countries represented - a 10% increase in attendance and a 24% increase in representation. […]
  • C Program to Find Total of Even IntegersC Program for Reading Integer Numberswe can give simple example to write C Program for reading Integer Numbers. The Various input formatting options for reading integers are experimented in the program shown in below C […]