Explain the Character operations in C language


Character can be (A-Z(or) a- z), digit (0-9), a white space, or a special symbol in C programming language.

Declaration

Following is the declaration for character operations in C programming −

char a= ‘A’; using a character constant.

Character input / output functions

The character input/output functions are explained below −

Example − char a;

scanf("%c", &a); printf ("%c", &a);
a = getchar ( ); putchar (a);
a = getch ( ); putch (a);

Example

Following is the C program for line counting using getchar() −

 Live Demo

#include <stdio.h>
/* count lines in input */
main(){
   int count, num;
   printf("enter multiple statements and Press cntrl+z:
");    num = 0;    while ((count = getchar()) != EOF)       if (count == '
')       ++num;    printf("%d
", num); }

Output

Following is the output of the program −

enter multiple statements and Press cntrl+z:
Hi
Hello
Welcome To
My World
^Z
4

Updated on: 24-Mar-2021

425 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements