Breaking

रविवार, 19 अप्रैल 2020

BCA 2nd Sem Notes - Standard function fopen(), fclose(),feof() fseek(),fewind() in C

  • 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)






  • UNIT-IV (Structures)
  • Definition





  • UNIT-V                                  (C Preprocessor)






  • UNIT-VI                                (File Handling)


  • Standard function



    Header file
    Description
    stdio.h                         Used to perform input and output operations like scanf() and printf().
    conio.h                          Used to perform console input and console output operations like clrscr() to clear the screen and getch() to get the character from the keyboard.
    string.h                 Used to perform string manipulation operations like strlen and strcpy.
    stdlib.h                      Used to perform standard utility functions like dynamic memory allocation using functions such as malloc() and calloc().
    math.h                    Used to perform mathematical operations like sqrt() and pow() to obtain the square root and the power of a number respectively
    time.h             Used to perform functions related to date and time like setdate() and getdate() to modify the system date and get the CPU time respectively.
    ctype.h                                                      Used to perform character type functions like isaplha() and isdigit() to find whether the given character is an alphabet or a digit. respectively
    stdarg.h                                                                          Used to perform standard argument functions like va_start and va_arg() to indicate the start of the variable-length argument list and to fetch the arguments from the variable-length argument list in the program respectively.
    signal.h                                      Used to perform signal handling functions like signal() and raise() to install signal handler and to raise the signal in the program respectively.
    setjmp.h   Used to perform jump functions
    locale.h                  Used to perform localization functions like setlocale() and localeconv() to set locale and get locale conventions respectively.
    errno.h                                         Used to perform error handling operations like errno() to indicate errors in the program by initially assigning the value of this function to 0 and then later changing it to indicate errors.
    assert.h                                 Used in program assertion functions like assert() to get an integer data type as a parameter which prints stderr only if the parameter passed is 0.

    Some header files details 

    1.stdio.h

    It stands for standard input and standard output used to perform input-output functions, some of which are:

    • printf()– Used to display output on the screen.
    • scanf()– To take input from the user.
    • getchar()– To return characters on the screen.
    • putchar()– To display output as a single character on the screen.
    • fgets()– To take a line as an input.
    • puts()– To display a line as an output.
    • fopen()– To open a file.
    • fclose()– To close a file.

    2.(conio.h)

    It is used to perform console input and console output operations like clrscr() to clear the screen and getch() to get the character from the keyboard.

    3.(math.h)

    The math header is of great significance as it is used to perform various mathematical operations such as:
    • sqrt() – This function is used to find the square root of a number
    • pow() – This function is used to find the power raised to that number.
    • fabs() – This function is used to find the absolute value of a number.
    • log() – This function is used to find the logarithm of a number.
    • sin() – This function is used to find the sine value of a number.
    • cos() – This function is used to find the cosine value of a number.
    • tan() – This function is used to find the tangent value of a number.

    4.(ctype.h)

    This function is popularly used when it comes to character handling.
    Some of the functions associated with <ctype.h> are:
    • isalpha() – Used to check if the character is an alphabet or not.
    • isdigit() – Used to check if the character is a digit or not.
    • isalnum() – Used to check if the character is alphanumeric or not.
    • isupper() – Used to check if the character is in uppercase or not
    • islower() – Used to check if the character is in lowercase or not.
    • toupper() – Used to convert the character into uppercase.
    • tolower() – Used to convert the character into lowercase.
    • iscntrl() – Used to check if the character is a control character or not.
    • isgraph() – Used to check if the character is a graphic character or not.
    • isprint() – Used to check if the character is a printable character or not
    • ispunct() – Used to check if the character is a punctuation mark or not.
    • isspace() – Used to check if the character is a white-space character or not.
    • isxdigit() – Used to check if the character is hexadecimal or not.

    5.(stdlib.h)

    Functions such as malloc(), calloc(), realloc() and free() can be used while dealing with dynamic memory allocation of variables.

    programm in file 
    / * Open, write and close a file : */
    # include <stdio.h>
    # include <string.h>
     
    int main( )
    {
        FILE *fp ;
        char data[50];
        // opening an existing file
        printf( "Opening the file test.c in write mode" ) ;
        fp = fopen("test.c", "w") ;
        if ( fp == NULL )
        {
            printf( "Could not open file test.c" ) ;
            return 1;
        }
        printf( "\n Enter some text from keyboard” \
                 “ to write in the file test.c" ) ;
        // getting input from user
        while ( strlen ( gets( data ) ) > 0 )
        {
            // writing in the file
            fputs(data, fp) ;  
            fputs("\n", fp) ;
        }
        // closing the file
        printf("Closing the file test.c") ;
        fclose(fp) ;
        return 0;        
    }

    OUTPUT:

    Opening the file test.c in write mode
    Enter some text from keyboard to write in the file test.c
    Hai, How are you?
    Closing the file test.c

     fseek() programm

    1. #include <stdio.h>  
    2. void main(){  
    3.    FILE *fp;  
    4.   
    5.    fp = fopen("myfile.txt","w+");  
    6.    fputs("This is javatpoint", fp);  
    7.     
    8.    fseek( fp, 7, SEEK_SET );  
    9.    fputs("sonoo jaiswal", fp);  
    10.    fclose(fp);  
    11. }  

    output


    This is sonoo jaiswal

    1. #include<stdio.h>  
    2. #include<conio.h>  
    3. void main(){  
    4. FILE *fp;  
    5. char c;  
    6. clrscr();  
    7. fp=fopen("file.txt","r");  
    8.   
    9. while((c=fgetc(fp))!=EOF){  
    10. printf("%c",c);  
    11. }  
    12.   
    13. rewind(fp);//moves the file pointer at beginning of the file  
    14.   
    15. while((c=fgetc(fp))!=EOF){  
    16. printf("%c",c);  
    17. }  
    18.   
    19. fclose(fp);    
    20. getch();    
    21. }    
    Output:
    this is a simple textthis is a simple text

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

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