C Program to Display same Source Code as Output

C Program to Display same Source Code as Output.


C Program t Disoplay same Source Code as Output Images-Pics-Photos-Snaps-Snapshots-Basic C Programs-Files in C-File Handling in C-File Operations in C-File Programs-C Language Programs-File Modes in C-General C Programs

A File represents a sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of data. There are 2 types of files.

1. Text files

2. Binary files

1. Text files
Text files are the normal .txt files that you can easily create using Notepad or any simple text editors.When you open those files, you'll see all the contents within the file as plain text. You can easily edit or delete the contents.

2. Binary files
Binary files are mostly the .bin files in your computer. Instead of storing data in plain text, they store it in the binary form (0's and 1's). They can hold higher amount of data, are not readable easily and provides a better security than text files.

File OperationsIn C, you can perform 4 major operations on the file, either text or binary:
Creating a new file
Opening an existing file
Closing a file
Reading from and writing information to a file

When working with files, we need to declare a pointer of type file. This declaration is needed for communication between the file and program.
                  FILE *fptr;

Opening a file is performed using the library function in the "stdio.h" header file: fopen( )

The syntax for opening a file in standard I/O is
         ptr = fopen("fileopen","mode")


--------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>
int main( )
{
    FILE *fp;
    char ch;
    fp= fopen(_FILE_,"r");
    do
    {
         ch = getc(fp);
         putchar(ch);
    }
    while(ch!=EOF);
    fclose(fp);
    return 0;
}

--------------------------------------------------------------------------------------------------------------------------

Output

--------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>
int main( )
{
    FILE *fp;
    char ch;
    fp= fopen(_FILE_,"r");
    do
    {
         ch = getc(fp);
         putchar(ch);
     }
     while(ch!=EOF);
     fclose(fp);
     return 0;
}



The _FILE_is Standard Predefined Macros in C Programming. This macro will expand to the name of current file path. Suppose we have saved this source code at path

    c://tc/bin/file 1.c then
    fp = fopen(_FILE_,"r"); will be expanded as
    fp = fopen("c://tc/bin/file1.c","r");



EmoticonEmoticon