<commit_before>#include <cs50.h>
#include <stdio.h>
#include <string.h>

// prototypes
int AppendToFile(void);
int ReadFromFile(void);
int WriteToFile(void);
int CopyFile(void);

int main()
{
    //AppendToFile();
    //ReadFromFile();
    //WriteToFile();
    CopyFile();

}


// COPY A FILE
// fopen() fgetc() fputc() fclose()
int CopyFile()
{

    // Open filepointer for reading
    FILE *source = fopen("file.csv", "r");
    if(source == NULL)
    {
        return 1;
    }

    // Open filepointer for writing
    FILE *copy = fopen("newfile.txt", "w");
    if(copy == NULL)
    {
        return 1;
    }

    // Read the source file and copy its contents to a new file
    char ch;
    while( (ch = fgetc(source)) != EOF )
    {
        //printf("%c", ch); // console debug
        fputc(ch, copy);
    }


    fclose(source);
    fclose(copy);<commit_msg>created a copy func using fread and fwrite<commit_after>#include <cs50.h>
#include <stdio.h>
#include <string.h>

// prototypes
int AppendToFile(void);
int ReadFromFile(void);
int WriteToFile(void);
int CopyFile(void);
int CopyFileFRead(void);

int main()
{
    //AppendToFile();
    //ReadFromFile();
    //WriteToFile();
    //CopyFile();
    CopyFileFRead();
}




// COPY A FILE USING fread() and fwrite()
// fopen()

int CopyFileFRead()
{

    // Open a file pointer to read data
    FILE *source = fopen("file.csv", "r");
    if (source == NULL)
    {
        printf("Error: Invalid file\n");
    }

    // Open a file pointer to copy data to
    FILE *copy = fopen("new_file.csv", "w");
    if(copy == NULL)
    {
         printf("Error: Invalid copy\n");
    }


    // use fread(<buffer>,<size>,<qty>,<file pointer>) to read the source
    char c;
    while(fread(&c, sizeof(char), 1, source))
    {
        fwrite(&c, sizeof(char), 1, copy);
    }


    // use fwrite(<buffer>, <size>, <qty>, <file pointer>) to copy the file

    fclose(source);
    fclose(copy);
    return 0;
}




// COPY A FILE USING fgetc() and fputc()
// fopen() fgetc() fputc() fclose()
int CopyFile()
{

    // Open filepointer for reading
    FILE *source = fopen("file.csv", "r");
    if(source == NULL)
    {
        return 1;
    }

    // Open filepointer for writing
    FILE *copy = fopen("newfile.txt", "w");
    if(copy == NULL)
    {
        return 1;
    }

    // Read the source file and copy its contents to a new file
    char ch;
    while( (ch = fgetc(source)) != EOF )
    {
        //printf("%c", ch); // console debug
        fputc(ch, copy);
    }


    fclose(source);
    fclose(copy);
{'fraction_non_alphanumeric': 0.1638639030113414, 'fraction_numerical': 0.004301916308173641, 'mean_word_length': 2.3925729442970822, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6481192', 'n_tokens_mistral': 921, 'n_tokens_neox': 886, 'n_words': 248}