Image

Imagemac05 wrote in Imagecprogramming

File I/O and storage

I have an assignment for a Data Structures class where I have to use a circular queue.



To read in information from a file to a temporary queue, I used:

In a .h file:

typedef struct element
{
  int idNum; //0-47
  char readWrite; //read or write
  int Tsector; //0-19
  int Ttrack; //0-199

  int tracksCrossed; //0-199
  int waitTime; // >0
} element;

element asQueue[MAXQSIZE];

void fnAddq( int front, int *rear, element item )
{
  //add an item to the queue

  *rear = (*rear+1) % MAXQSIZE;

  if( front == *rear ) //this does something if the queue is full
  {
    fnQueueFull( rear );
    return;
  }

  asQueue[*rear] = item;
}


In a .cpp file in the same project:

fscanf( pDiskIoFile, "%d%c%d%d", &asTempItem[currentQindex].idNum, &asTempItem[currentQindex].readWrite, 
  &asTempItem[currentQindex].Tsector, &asTempItem[currentQindex++].Ttrack ); 

numOfVals++; 

fnAddq( frontQ, &rearQ, asTempItem[currentQindex] ); 


Next, I wanted to know if my data was actually in there or not. So, since I'm not familiar with how to do this using the debugger in .Net, I put:

printf( "%d\n%c\n%d\n%d\n", &asTempItem[currentQindex-1].idNum, &asTempItem[currentQindex-1].readWrite, 
  &asTempItem[currentQindex-1].Tsector, &asTempItem[currentQindex-1].Ttrack );


The result? Gibberish.

The data in my file is:


1 r 0 40
2 r 12 122
3 w 19 5
4 w 17 97
5 r 8 27


I was expecting the first line of the file to have been added to the queue. Any ideas on why this isn't working? Or for anything else I could try?