NTech

Menu
  • Home
  • Technology
    • Internet
    • Market
    • Stock
  • Downloads
    • Dvd
    • Games
    • Software
      • Office
  • Parent Category
    • Child Category 1
      • Sub Child Category 1
      • Sub Child Category 2
      • Sub Child Category 3
    • Child Category 2
    • Child Category 3
    • Child Category 4
  • Featured
  • Health
    • Childcare
    • Doctors
  • Uncategorized

Sunday, 16 August 2015

C program to copy contents of one file to another file

By ntech23:28 No comments
#include <stdio.h>
#include <stdlib.h> // For exit()

int main()
{
    FILE *fptr1, *fptr2;
    char filename[100], c;

    printf("Enter the filename to open for reading \n");
    scanf("%s", filename);

    // Open one file for reading
    fptr1 = fopen(filename, "r");
    if (fptr1 == NULL)
    {
        printf("Cannot open file %s \n", filename);
        exit(0);
    }

    printf("Enter the filename to open for writing \n");
    scanf("%s", filename);

    // Open another file for writing
    fptr2 = fopen(filename, "w");
    if (fptr2 == NULL)
    {
        printf("Cannot open file %s \n", filename);
        exit(0);
    }

    // Read contents from file
    c = fgetc(fptr1);
    while (c != EOF)
    {
        fputc(c, fptr2);
        c = fgetc(fptr1);
    }

    printf("\nContents copied to %s", filename);

    fclose(fptr1);
    fclose(fptr2);
    return 0;
}
 
 
 
 
 
 
Output: 

Enter the filename to open for reading
a.txt
Enter the filename to open for writing
 b.txt
Contents copied to b.txt
 
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Pages

  • Home

Popular Posts

  • What Is A Motherboard? What Are The Different Components Of A Motherboard?
    What Is A Motherboard? What Are The Different Components Of A Motherboard? Image: Wikipedia Short Bytes: A motherboard acts as a pl...
  • Run Windows 98 And Linux In Your Web Browser, Thanks To JavaScript And NodeJS
    Run Windows 98 And Linux In Your Web Browser, Thanks To JavaScript And NodeJS     Short Bytes: A coder, known as Fabian on GitHub, ...
  • Biggest Rivalries in Computing History
    Pepsi vs. Coke, Edison vs. Tesla, Star Wars vs. Star Trek, history is filled with famous rivalries, but few have matched the intensity and...
  • PHP vs Ruby which programming language is better for web development
    PHP vs Ruby which programming language is better for web development PHP and ruby are trending scripting languages for the web servers...
  • Master Python: Save over 95% on 50+ hours of training
    Master Python: Save over 95% on 50+ hours of training For prog...
  • How to Right Click using the Keyboard
    Looking for the right click keyboard command ? It’s not often you’re left without a mouse, a trackball, or a touch pad, but there are...
  • It’s Official: Android N Is Android Nougat
    It’s Official: Android N Is Android Nougat Short Bytes: After months of speculations and guesses, Google has finally revealed the offi...
  • All over the world use Uptodown to get instant access to a huge catalogue of apps for a number of operating systems.
    https://en.uptodown.com
  • Happy Birthday Steve Jobs: The Genius Life Of Apple’s Founder
    Happy Birthday Steve Jobs: The Genius Life Of Apple’s Founder     Short Bytes: The life of Steve Jobs wasn’t a straight line. He fa...
  • 13 most useful Mac shortcuts that will help you do everything quickly
    13 most useful Mac shortcuts that will help you do everything quickly       The 13 most useful Mac shortcuts that lets y...

Recent Posts

Text Widget

Pages

  • Home

Blog Archive

  • ►  2019 (2)
    • ►  May (1)
    • ►  April (1)
  • ►  2017 (7)
    • ►  July (1)
    • ►  April (3)
    • ►  March (3)
  • ►  2016 (50)
    • ►  October (1)
    • ►  September (4)
    • ►  July (2)
    • ►  June (6)
    • ►  April (2)
    • ►  March (5)
    • ►  February (28)
    • ►  January (2)
  • ▼  2015 (9)
    • ▼  August (9)
      • Command Line Argument C Program
      • C program to copy contents of one file to another ...
      • Google announces massive reorganization, becomes s...
      • Windows 10 vs. Windows 8.1 vs. Windows 7 Performance
      • Fingerprint scanners on Android phones are far les...
      • C program to Calculate Factorial of a Number Using...
      • FIND FACTORIAL OF A NUMBER USING RECURSION IN C PR...
      • Intel Core i7-6700K "Skylake" CPU Review
Powered by Blogger.

Text Widget

About Me

ntech
View my complete profile

Copyright © NTech | Powered by Blogger
Design by Flythemes | Blogger Theme by NewBloggerThemes.com