SQL PHP HTML ASP JavaScript articles and free scripts to download
 

putchar() to display single char

We can display one character by using putchar function in C programming language. WE have already seen how to send output by using printf() function.

Moving the crusher to next line

As we know we can move the crusher to beginning of next line by using \n , we will use the putchar function to give a line break like this

putchar('\n');

We will take one input char by using getchar and then will display the same bit by putchar function here is the code.

printf( "Enter any char from keyboard ");
putchar ('\n'); // Move the crusher to next line
var = getchar();
putchar(var);

Using the basics of above code we will develop a program to display lowercase letter if user enters uppercase letter and vise versa. For this program we will use toupper() and tolower() function which are part of the ctype library so we will include ctype.h ( header file ) at the starting of the program. Here is the complete code.

#include <stdio.h>
#include <ctype.h>
int main(void){
char var;
printf( "Enter any char from keyboard ");
putchar ('\n'); // Move the crusher to next line

var = getchar();
if(islower(var))
{
putchar(toupper(var));
}
else
{
putchar(tolower(var));
}

return 0;
}




Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Join Our Email List
Email:  
For Email Newsletters you can trust
Basic of C
C Sections