This blog is under construction

Saturday, 17 March 2012

iscntrl example in C

Header file:
    ctype.h

Synopsis:
    int iscntrl (int c);

Description:
    Checks whether the given input is a control(non-printing character) character or not.

Return Value:
    TRUE(non-zero value) on success
    0 on failure


iscntrl function C example:


  #include<stdio.h>
  #include<ctype.h>
  int main() {
        char c;
        printf("Enter your input:");
        /* cntrl char - non printing character(eg.: give ESC as i/p) */
        c = getchar();

        if (iscntrl(c))
                printf("Given input is a cntrl character\n");
        else
                printf("Given input is not a cntrl character\n");

        printf("Return value from iscntrl: %d\n", iscntrl(c));
        return 0;
  }



  Output:
  /* give esc as input */
  jp@jp-VirtualBox:~/cpgms$ ./a.out
  Enter your input:^[
  Given input is a cntrl character
  Return value from iscntrl: 2

  jp@jp-VirtualBox:~/cpgms$ ./a.out
  Enter your input:a
  Given input is not a cntrl character
  Return value from iscntrl: 0


No comments:

Post a Comment