Getting Started With C

File Input Operations:

Reading Characters:
          1)fgetc: Reads a single character from a file.
          getc: Similar to fgetc, reads a character from a file.
          Reading Lines:

          2)fgets: Reads a line of text from a file.
          Reading Formatted Data:

          3)fscanf: Reads formatted data from a file.
          scanf: Reads formatted data from a string.
  
        

File Output Operations:

Writing Characters:
1)fputc: Writes a single character to a file.
          putc: Similar to fputc, writes a character to a file.
          Writing Strings:
          
          2)fputs: Writes a string to a file.
          puts: Similar to fputs, writes a string to a file.
          Writing Formatted Data:
          
          3)fprintf: Writes formatted data to a file.
          sprintf: Writes formatted data to a string.
          
Writing Binary Data:

1)fwrite: Writes a block of data to a file.

  • Examples :

    Program.c


  • Output:

                Characters read from the file: A B
                Line read from the file: ABHello, File!
                Formatted data read from the file: 65 *
                Binary data read from the file:
                 1699234369 745499756 1818838560 168632677 1836216134
               
            

    Resources :

    Test Your Knowledge
    Choose The

    With supporting text below as a natural lead-in to additional content.

    Q1. In C programming, which file mode in the fopen function is used to open a file for both reading and writing, and if the file does not exist, it is created?

    Q2. What is the purpose of the fprintf function in C file operations?