<commit_before>#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[]){
	char c;
	int read_count;
	for (int i = 1; i < argc; i++){
		if (!fork()){
			int fd1 = open(argv[i], O_RDONLY);
			char *dest_dir;
			asprintf(dest_dir, "%s%s", argv[argc], argv[i]);
			int fd2 = open(dest_dir, O_WRONLY | O_APPEND | O_CREAT);
			while ((read_count = read(fd1, &c, 1))){
				write(fd2, c, 1);
			}
			
			close(fd1);
			close(fd2);
		}
	}
	
	for (int i = 1; i < argc; i++){
		int status;
		wait(&status);
	}
	return 0;
}<commit_msg>81104: commented and graded the first C task<commit_after>#define _GNU_SOURCE

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/wait.h>
// These headers are necessary.

// Concurrency is done right!  (+0.3)

int main(int argc, char *argv[]){
	char c;
	int read_count;
	//   The number of arguments is `argc`, so you should be going up to the
	// last argument (i.e. `argc - 1`), but NOT including it.  (-0.2)
	for (int i = 1; i < argc - 1; i++){
		if (!fork()){
			int fd1 = open(argv[i], O_RDONLY);
			char *dest_dir;
			// The last argument is arg[argc - 1], NOT arg[argc].
            // `asprintf` accepts as first argument a double pointer.
			asprintf(&dest_dir, "%s%s", argv[argc - 1], argv[i]);
			//   It would be nice to add `O_TRUNC` and a file mode as the
			// second argument.
			int fd2 = open(dest_dir, O_WRONLY | O_TRUNC | O_CREAT);
			while ((read_count = read(fd1, &c, 1))){
                //   `write` accepts as second argument a pointer, not a char.
                // (-0.1)
				write(fd2, &c, 1);
			}

            //   You ought to deallocate the allocated storage by `asprintf`
            // but this is not a concern right now.
            free(dest_dir);
			close(fd1);
			close(fd2);
		}
	}

	for (int i = 1; i < argc - 1; i++){
		int status;
		wait(&status);
	}
	return 0;
}

// Total points for this task:  2/2
{'fraction_non_alphanumeric': 0.16164241164241164, 'fraction_numerical': 0.02079002079002079, 'mean_word_length': 2.5847299813780262, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 10, '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': '1412176', 'n_tokens_mistral': 819, 'n_tokens_neox': 734, 'n_words': 237}