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;
}

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer