Breaking

शनिवार, 4 अप्रैल 2020

BCA 2nd Sem Notes -Standard library function

  • UNIT-I (Array)
Definition
Declaration & initialization of 1D 
Accessing array elements
Displaying array elements
Sorting arrays
Arrays and function
Declaration & initialization of 1D
Accessing and Displaying
Memory representation of array [Row Major, Column Major]
Multidimensional array

  • UNIT-II (Pointers)
  • Definition


    Declaration & initialization
    Indirection operator
    address of operator
    pointer arithmetic
    dynamic memory allocation
    arrays and pointers
    function and pointers







  • UNIT-III (Strings)



  •   strlen(),strcpy(),       strcat() ,strcmp()

  • UNIT-IV (Structures)
  • Definition

  • UNIT-V                                     (C Pre-processor)


  • UNIT-VI                                (File Handling)



  • Definition of Files,
    Opening modes of files
    Standard function
    fopen(), fclose(),             feof()  fseek(),                    fewind()
    Using text files
    fgetc(), fputc(), fscanf()

     Standard library function


    The standard 'C' library provides various functions to manipulate the strings within a program. These functions are also called as string handlers. All these handlers are present inside <string.h> header file.


    strlen()                      This function is used for finding a length of a string. It returns how many characters are present in a string excluding the NULL character.

    strcat(str1, str2)      This function is used for combining two strings together to form a single string. It Appends or concatenates str2 to the end of str1 and returns a pointer to str1.


    strcmp(str1, str2)        This function is used to compare two strings with each other. It returns 0 if str1 is equal to str2, less than 0 if str1 < str2, and greater than 0 if str1 > str2.


    strlen(), strcpy(), strcat(), strcmp()


    strlen()
    strlen() stands for string length. This function is used to find a number of characters stored in a string variable or string constant. This function doesn’t count the null character.
    The header file required for this function is “string.h”--
    Program to demonstrate the use of strlen() function
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char studentname[20]=”Aryan”;
    int n;n=strlen(studentname);printf(“\nNumber of characters=%d”,n);
    return(0);
    }
    Output
    Number of characters=5

    strcpy()
    strcpy() stands for string copy. This function is used to copy value of one string variable or string constant in another string variable.
    The header file required for this function is “string.h”.


    The syntax for strcpy() is

    strcpy(Str_Target,Str_Source);

    Str_Target is the string variable in which wants to store the value.
    Str_Source is the string value that we want to store in string variable Str_Target. This value can be a string constant or a string variable. Size of Str_Target should be larger than or equal to the size of value to be stored in the variable.

    We can’t assign value to a string variable directly as
    char name[20];
    name=”Aryan”;
    In place of assignment operator =, we need to use strcpy() function.
    char name[20];
    strcpy(name,”Aryan”);
    Program to demonstrate the use of strcpy() function
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char studentname[20];
    strcpy(studentname,”Amit”);
    printf(“\nStudentname=%s”,studentname);
    return(0);
    }

    strcat()

    strcat() stands for string concat. This function is used to combine values of two string variables together.

    The header file required for this function is “string.h”.

    The syntax for strcat() function is
    strcat(Str_Target,Str_Source);
    Str_Target is the string variable whose value we want to combine with some other string value.
    Str_Source is the string value which we want to combine with the value of string variable
    Str_Target. This value can be a string constant or a string variable. The size of Str_Target should be larger than or equal to the combined size of Str_Target and Str_Source.
    Program to demonstrate the use of strcat() function

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char studentname[20]=”Aryan”;
    clrscr();
    strcat(studentname,” Singh”);
    printf(“\nStudentname=%s”,studentname);
    return(0);
    }
    Output
    Studentname=Aryan Singh
     strcmp()


    strcmp()  stands for string compare. This function is used to compare the value of one string value with another string value.



     The header file required for this function is “string.h”.

    Program to demonstrate the use of strcmp() function

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    char studentname[25];
    strcpy(studentname,”Amita”);
    if(strcmp(studentname,”Amit”)= =0)
    cout<<”\nWelcome”;
    else
    cout<<”\nBye”;
    return(0);
    }

    Output

    Bye


    कोई टिप्पणी नहीं:

    एक टिप्पणी भेजें