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...
  • Fingerprint scanners on Android phones are far less secure than on iPhones
    The  Samsung Galaxy S5's fingerprint reader security vulnerabilities  were well documented over a year ago. But if you were hoping t...
  • FREE! That’s Right, I’m Giving Away MILLIONS of FREE Microsoft eBooks again! Including: Windows 10, Office 365, Office 2016, Power BI, Azure, Windows 8.1, Office 2013, SharePoint 2016, SharePoint 2013, Dynamics CRM, PowerShell, Exchange Server, System Center, Cloud, SQL Server and more!
    FREE! That’s Right, I’m Giving Away MILLIONS of FREE Microsoft eBooks again! Including: Windows 10, Office 365, Office 2016, Power BI, A...
  • 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...
  • Evolution of Microsoft’s Windows OS from Windows 1.0 to Windows 10
    Windows 1.0 to 10: The changing face of Microsoft’s landmark Windows operating system Microsoft, the leader in software and opera...
  • 10 Best Free VPN Services Of 2016: Which One Shall I Choose?
    10 Best Free VPN Services Of 2016: Which One Shall I Choose?   Short Bytes: Due to restrictions and localization of different interne...
  • Master Python: Save over 95% on 50+ hours of training
    Master Python: Save over 95% on 50+ hours of training For prog...
  • 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...
  • Hub vs Switch: Comparison And Difference Between Networking Devices
      Hub vs Switch – which one is better? Which one should be used for faster communication? Which one is more secure? Well, we answer a...

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