Question

Write a simple C/C++ function, void copy_create(char * file), that would take one text file name...

Write a simple C/C++ function, void copy_create(char * file), that would take one text file name as parameter and create a file named “duplicate.txt”, having the content of the file name sent as parameter.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

void copy_create(char * file) {
    FILE *f = fopen(file, "r");
    if (f) {
        FILE *w = fopen("duplicate.txt", "w");
        char ch;
        while ((ch = (char)fgetc(f)) != EOF) {
            fputc(ch, w);
        }
        fclose(w);
        fclose(f);
    } else {
        printf("%s does not exists!\n", file);
    }
}

int main() {
    copy_create("input.txt");
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Write a simple C/C++ function, void copy_create(char * file), that would take one text file name...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a simple C/C++ function named int match_content(char * file1, char *file2) that would take two...

    Write a simple C/C++ function named int match_content(char * file1, char *file2) that would take two text file name as a parameter, and return 1, if the content is same in both the files, 0 otherwise. Your program should be case insensitive and should support all the ascii characters.

  • According to Wikipedia , a comma-separated values (CSV) file is a delimited text file that uses...

    According to Wikipedia , a comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. A CSV file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format. A company has text data that is not...

  • Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of...

    Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of text file to write to Outputs: none File Outputs: 1. A text file containing all the permutations of the anagram Banned Functions: perms(), permute(), ipermute(), nchoosek (), combnk() Background: You guys know what do. You are professional MATLAB now, you got this! Function Description: Given a string, recursively determine all the unique ways to rearrange the letters. (i.e al the unique permutations). For example,...

  • Write in C language 5. [8] Write a function with prototype » void string_copy(const char source[],...

    Write in C language 5. [8] Write a function with prototype » void string_copy(const char source[], char destination[], int n); This function copies string source to string destination. Parameter n represents the size of array destination. If the latter array is not sufficiently large to hold the whole source string then only the prefix of the string which has room in the latter array should be copied. Note that after copying, the null character should also be included to mark...

  • Code in C++: Please help me fix the error in function: void write_account(); //function to write...

    Code in C++: Please help me fix the error in function: void write_account(); //function to write record in binary file (NOTE: I able to store data to a txt file but however the data get error when I try to add on data the second time) void display_all(); //function to display all account details (NOTE: This function is to display all the info that save account.txt which is ID, Name, and Type) void modify_account(int); //function to modify record of file...

  • use c code to Develop a function void printToggled(char str[]) that gets a string as a...

    use c code to Develop a function void printToggled(char str[]) that gets a string as a parameter and prints every lowercase character as an uppercase one and vise versa. For example, if the string submitted as a parameter is Hello WorlD! The function should print hELLO wORLd! Hint:answer must include output

  • using Python please reverse file Writ te a function named reverse file. This function will take...

    using Python please reverse file Writ te a function named reverse file. This function will take one parameter which will be the file name of the file to reverse. This function will open the file with the name passed in as a parameter and will print out all the lines of the file in reverse order. Below are a few examples: If the files lines.brt looks like: orange apple orange apple orange apple grape Then the following should look like...

  • USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is...

    USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...

  • C Programming 23 points Write a function for the following specs: type: void parameters: FILE", int[],...

    C Programming 23 points Write a function for the following specs: type: void parameters: FILE", int[], int size • Behavior: Write the text value of each element from the int[] to the file File format: an integer on each line of the file. Le: 4 3 1 5

  • TASK: to receive this checkpoint, you must write a simple function that displays a text message...

    TASK: to receive this checkpoint, you must write a simple function that displays a text message on the screen. The function signature should be: void print_to_screen(char *message); This function should accept a string, and write each character of the string to the screen, and increase the current_screen_x variable for each character printed. You will need to maintain a pointer to the current line on the screen, as well as the position on that line. You could do this with definitions...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT