Ok...my code is fixed, to the poin that it compiles correctly, but it does not work.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *in, *in1, *in2, *out1, *out2;
int numsplit = 2;
int ccount;
char buff1;
char buff;
int count;
int aftsplit;
int usage() {
puts("Improper usage...\nUsage: fsplit -s(plit)-a(mmend) <file(1)> (<file2>)");
return 0;
}
int main(int argc, char *argv[], char *file[]) {
if(argc < 2) {
usage();
}
if(argv[1] == "-s") {
if((in = fopen(argv[2], "rb")) == NULL) {
printf("Error opening %s\n", argv[2]);
}
if((out1 = fopen("/tmp/.out1", "wb")) == NULL) {
puts("Error opening /tmp/.out1");
}
if((out2 = fopen("/tmp/.out2", "wb")) == NULL) {
puts("Error opening /tmp/.out2");
}
while((buff = getc(in)) != EOF) {
count++;
}
aftsplit = (count / numsplit);
while(ccount <= count) {
buff = getc(in);
while(count <= aftsplit) {
putc(buff, out1);
ccount++;
}
putc(buff, out2);
}
fclose(out1);
fclose(out2);
fclose(in);
}
else if(argv[1] == "-a") {
if((in1 = fopen(argv[2], "rb")) == NULL) {
printf("Error opening %s", argv[2]);
}
if((in2 = fopen(argv[3], "rb")) == NULL) {
printf("Error opening %s", argv[3]);
}
if((out1 = fopen("/tmp/.out", "wb")) == NULL) {
printf("Error, /tmp/.out is not empty...please delete and try again\n");
}
while((buff = getc(in1)) != EOF) {
putc(buff, out1);
}
while((buff1 = getc(in2)) != EOF) {
putc(buff1, out1);
}
printf("Done combining %s and %s", argv[2], argv[3]);
fclose(in1);
fclose(in2);
fclose(out1);
}
/* else {
if((argv[1] != "-s") && (argv[1] != "-a")) {
puts("Error...you did not choose to either -s(plit) or -a(ppend)");
}
} */
return 0;
}