Skip to content
Snippets Groups Projects
Commit 0d5236a4 authored by Vishnu Menon's avatar Vishnu Menon :bulb:
Browse files

read file provided via argument

parent c34e8c08
No related branches found
No related tags found
No related merge requests found
build/
tmp/
\ No newline at end of file
#include <stdio.h>
int main(void)
// my everlasting commitment to ridding code of magic numbers :)
#define MEMORY_SIZE 65535
#define BUFFER_SIZE 32767
int memory[MEMORY_SIZE];
// no idea what these are yet, when i figure that out i'll rename them something better
int sp, fp = MEMORY_SIZE;
int img, but, lab, tab = 0; // renaming these too
int main(int argc, char* argv[])
{
printf("Hello world!\n");
if (argc < 2) {
printf("Error: Did not specify file.");
return 1;
} else if (argc > 2) {
printf("Error: Too many arguments!");
return 1;
}
FILE *executable = fopen(argv[1], "r");
if (executable == NULL) {
printf("Error: Could not locate %s", argv[1]);
return 1;
}
char buffer[BUFFER_SIZE];
while(fgets(buffer, BUFFER_SIZE-1, executable) != NULL) {
printf("%s", buffer);
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment