this is a work in progress so it does not do anything and its mostly a mess that i need to clean up but, im just trying to get it to a "working but barely level", and im just lost on this error, i have just two arrays set to size 16, and whenever i want to loop through them and do array[pos] I throw the error in the title, and i might just be missing somthing very basic but I'm just totally lost
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
// global instalization (to be edited?)
#define pages 256
#define page_size 256
#define memory_size pages * page_size
#define TLB_SIZE 16
int page_table[pages];
int TLB[TLB_SIZE];
int TLB_frame[TLB_SIZE];
int main(int argc, char *argv[])
{
// BASIC INTIALIZATION FOR PAGE AND OFFSET, AND FILE, ADDRESS
char *address;
int page = 0;
int offset = 0;
size_t size = 0; // filler variable;
int eof=0; // end of file;
FILE* addresses;
addresses = fopen(argv[1], "r");
while (eof = getline(&address,&size,addresses) != EOF)
{
int TLB_frame = 0;
int frame = 0;
int pos;
page = atoi(address) / 256 ;
offset = atoi(address) % 256;
printf("here is the page number for %s\n", address);
printf("%d\n", page);
printf("here is the offset for %s\n", address);
printf("%d\n", offset);
for (pos = 0; pos < TLB_SIZE; pos++)
{
if(TLB[pos] == page)
{
frame = TLB_frame[pos];
}
}
}
}
again this doesnt do anything its just a work in progress, and theres probably alot of unnecessary things
errors
error: subscripted value is neither array nor pointer nor vector
46 | frame = TLB_frame[pos];
if i mess with the pos variable the same error will throw on the array loop up above
You declared an array in the file scope
int TLB_frame[TLB_SIZE];
then in the while loop
while (eof = getline(&address,&size,addresses) != EOF)
{
int TLB_frame = 0;
//...
you redeclared the name TLB_frame
. So within this block scope the name TLB_frame
does not denote the array declared in the file scope. It is a scalar object of the type int
.
Also it seems the condition in the while statement should be
while ( ( eof = getline(&address,&size,addresses) ) != EOF)
Pay attention to that it is a bad idea to define macto names using lower case letters as for example in this directive
#define pages 256
Use upper case letters.