Computer >> Computer tutorials >  >> Programming >> C programming

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 −

Explain the Character operations in C language

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() −

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

Output

Following is the output of the program −

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