Saturday, June 20, 2020

Library Functions in C

Library functions are those functions which are pre-defined by compiler of C language. Some of the library functions are given below:
  1. Input / Output function (define in standard input/output stdio.h)
    Input/Output function is define in stdio.h header file. In C language 3 Input and 3 Output function are available for input and output of any data.
    Input Function
    • getchar()
      getchar() function is used to take single input charater data.
      Syntax: variable name=getchar();
      Example: x=getchar();
    • gets()
      gets() function is used to take multiple input charater data.
      Syntax: gets(variable name);
      Example: gets(name);
    • scanf()
      scanf() function is used to take all type of input data such sas (character data , string data , numric data).
      Syntax: scanf("Control string",&variable1,&variable2.....);
      Example: scanf("%d%f",&x,&y);

    Output Functions
    • putchar()
      putchar() function is used to print single charater data. It is output function.
      Syntax:putchar(variable name);
      Example: putchar(x);
    • puts()
      puts() function is used to print multiple character data (string).
      Syntax: puts(variable name);
      Example: puts(name);
    • printf()
      printf() function is used to print all type of data such as (character data , string data , numric data) on the screen.
      Syntax: printf("Control string",variable1,variable2.....);
      Example: printf("sum=%d",sum);
                       printf("sum of number",sum);
                       printf("%d",sum);
  1. Mathematical Function (define in math.h)
    These functions are used for mathematical operation.Include "math.h" header file before main() function for using these functions. These functions are:
    • sqrt():This function is used to find out square root of any number.
      Syntax: sqrt(argument);
      Example: sqrt(x);
    • pow(): pow() function is to find power of any number.
      Syntax: pow(argument1 , argument2);
      Example: pow(x,y); (i.e xy)
    • abs(x): This function return absolute number (positive number) of any numeric number.
      Syntax: abs(argument);
      Example: abs(-10); (i.e return 10)
  2. String function
    String function is used to manipulate or format the sting. String is a group of characters. Include "string.h" header file before main() function for using these functions.These functions are :
    • strlen(): This function is used to return the length of string.
      Syntax: strlen(argument);
      Example: x=strlen("Hello");
    • strcat(): This function is used to concate two string.
      Syntax: strcat(s1 , s2));
      Example: x=strlen("Hello" , "world");
    • strcpy(): This function is used to copy one string into second string.
      Syntax: strcpy(s1 , s2));
      Example: x="hello"; y="world"; strcpy(x , y);
    • strcmp(): This function is used to compair the length between two string.
      Syntax: strcmp(s1 , s2)); (i.e return 0 for s1=s2 , -1 for s1s2)
      Example: x=strcmp("hello" , "Helloworld"); return -1

No comments:

Post a Comment