File Handling Example Programs in C language

This section contains solved programs on C Language File Handling. Using these programs we will learn creating, writing, copying, moving, and deleting contents and files.

C File Handling Examples

Here you will find set of solved programs on file handling in c programming language like creating and opening file in binary or text mode, writing text, object into file, reading text, object from file, editing existing file, renaming an existing file, removing an existing file, copy one file’s content to another, displaying content of the file on output screen, getting size of the file, converting text into lower and upper case etc. By learning these file handling programs/examples you could be an expert in c programming language.

Example of FILE, fopen, fclose, fgetc, fputc, fgets, fputs, fseek, fwrite, fread, eof

All programs contain detailed description about the implemented logic, output on different phases, and explanation of programs and outputs.

List of C File Handling Programs

  1. C program to find number of lines in a file.
    This program will read a file and find the total number of file in it using C program.
  2. C program to create, open and close a file.
    This C file handling program will create, open a file and then close the file.
  3. C program to write text (characters) into file and print.
    This C file handling program will create a file in write mode and write the text characters (character by character) into the file and then read character by character from the file.
  4. C program to print given number of lines of a file (like head command in Linux).
    This C file handling program will print the number of lines (passed through the command line argument) on the output screen, just like a HEAD command in linux.
  5. C program to print contents in reverse order of a file (just like TAC command in Linux).
    This C program will print the content of the file in reverse order, just like TAC command in Linux.
  6. C program to compare contents of two files.
    This C program will read the content of two file and compare them, content will be read character by character and compare by the same way (character by character).
  7. C program to copy number of bytes of from a specific offset to another file.
    This C file handling program will open a file in read mode and copies specified bytes from given offset and write them into another file.
  8. C program to read Content of a File using getc() using C Program.
    This program will read the content of the file using getc() function.
  9. C program to convert All Characters in Upper Case of a File using C Program.
    This program will read the content a file and convert them into uppercase.
  10. C program to delete a specified file using remove() function
    In this program, we will delete a specified file using the remove() function. The remove() function returns 0, if file deleted successfully.
  11. C program to delete a specified file using the system() function
    In this program, we will delete a specified file using the system() function by passing the "rm" command.
  12. C program to remove a specified empty directory using the remove() function
    In this program, we will remove a specified empty directory using the remove() function.
  13. C program to remove an empty directory
    In this program, we will read the name of the empty directory, and then will remove the given empty directory using the system() function by specifying the "rmdir" command.
  14. C program to remove a non-empty directory using the system() function
    In this program, we will read the name of the non-empty directory, and then we will remove the given non-empty directory using the system() function by specifying the "rm" command.
  15. C program to check a given filename is a directory or not
    Read the name of the file and check whether it is file is a directory or not.
  16. C program to remove a specific line from the text file
    Read the line number from the user, and delete the specific line from the existing file. Then print the modified content file.
  17. C program to replace the specified line in an existing text file
    Read the line number from the user, and then replace the content-specific line with new text in the existing file. Then print the modified content file.
  18. C program to append the content of one file to the end of another file
    Given a file, we have to append the content of this existing file to the end of another exiting text file and then print the modified content of the file.
  19. C program to print the list of files of a directory
    Given a path of the directory, we have to print the list of files of a directory.
  20. C program to print the list of files and subdirectories of the current directory
    Given a path of the directory, we have to print the list of files and subdirectories of a current directory.
  21. C program to check a specified directory exists or not
    Given a path of the directory, we have to check whether the directory exists or not.
  22. C program to check a specified file exists or not
    Given a file path, we have to check whether a specified file exists or not.
  23. C program to check a specified file exists or not using the stat() function
    Given a file path, we have to check whether a specified file exist or not using the stat() function.
  24. C program to check a specified file exists or not using the access() function
    Given a file path, we have to check whether a specified file exist or not using the access() function.
  25. C program to check a specified file has read, write, and execute permission or not
    Given a file path, we have to check whether a specified file has, read, write, and execute access or not.
  26. C program to create a directory using mkdir() function
    Input the name (path) of the directory, and then we will create the given directory using the mkdir() function.
  27. C program to create a directory using system() function
    Input the name (path) of the directory, and then create the directory using the system() function.
  28. C program to remove an empty directory using rmdir() function
    Input the name of the directory (path) and then remove the given empty directory using the rmdir() function.
  29. C program to rename a file using the rename() function
    Read the old and new filenames and then rename the given file using rename() function.
  30. C program to rename a file using the system() function
    Read the old and new filename, and then rename the given file using the system() function by specifying the "mv" command.
  31. C program to change the permissions of file using system() function
    Given a file, we have to change the permissions of the file using the system() function by specifying the "chmod" command.
  32. C program to capitalize the first letter of every word in a file
    Here, we will read data from a file and capitalize the first letter of every word and update data into the file.



Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.