Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/splitfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
#define SIZE_LNBUF 255 //line buffer max size
#define SIZE_TXBUF 5000 //text file buffer for each split file

int main() {
int main(int argc, char *argv[]) {
int bufsize = 0;
int runs = 0;

char filename[SIZE_FN] = "";
char lnbuf[SIZE_LNBUF] = "";

char *txbuf = malloc(SIZE_TXBUF); //allocate split file buffer
Expand All @@ -18,8 +17,24 @@ int main() {
return EXIT_FAILURE;
}

printf("Enter file name to be split: ");
scanf("%s", filename);
if (argc < 2)
{
fprintf(
stderr,
"Error: Missing argument. Usage %s <filename>\n", argv[0]
);
return EXIT_FAILURE;
}
else if (argc > 2) {
fprintf(
stderr,
"Error: Too many arguments. Usage %s <filename>\n", argv[0]
);
return EXIT_FAILURE;
}

/* gets file name from argument 1 */
char *filename = argv[1];

FILE *readpoint = fopen(filename, "r"); //open fstream, read input file
if (readpoint == NULL) {
Expand Down