Hey guys. I'm new here. I have an assignment to read from a file and emulate a computer (moving around imaginary registers, moving RAM around, etc.)
I have two file pointers. one is in my main function and one is in a different function.
here is the code up to the first error:
Code:
#include <stdio.h>
#include <stdlib.h>
#define INPUT_FILE "interpreter.txt"
FILE *fp, *rp;
int registers[10], ram[1000], freq[10], instruction, lines;
void decMack0();
void decMack1();
void decMack2();
void decMack3();
void decMack4();
void decMack5();
void decMack6();
void decMack7();
void decMack8();
void decMack9();
void output();
int s, a, d, n, l;
int main()
{
fp = fopen(INPUT_FILE, "r");
if (fp == NULL)
{
printf("Can't open %s\n", INPUT_FILE);
getchar();
exit(1);
}
fscanf(fp, "%d", &lines);
printf("%d", fp);
reader();
while(!feof(fp))
here is the code for my second function:
Code:
reader()
{
int i=0;
int f=0;
while(!feof(rp)){
rp = fopen(INPUT_FILE, "r");
fscanf(rp, "%d", &f);
f = ram[i];
i++;
}
fclose(rp);
return;
}
for some reason, when I debug it, it doesn't seem to like the while loops. it won't even load the file once it sees that. when i print the pointers, fp and rp, it has a huge number (435557) something like that. can anyone see what I'm doing wrong? any help would be appreciated.