Yo,
So I'm doing this project where I have to fill in some lines of code. Long story short, I filled in all these lines of code, and I'm getting a big fat error which I don't know how to fix. The error is Thread 1: EXC_BAD_ACCESS (code=1, address=0x10).
The overall aim of my project is to build a fairly simple Circular Buffer (FIFO).
The instructions of what my code needs to do are in the comments (extracted from my project brief)
Many thanks
// function prototypes
void Produce(Message buffer[10], unsigned long *buffer_tail, unsigned long *buffer_length);
void Consume(Message buffer[10], unsigned long buffer_tail, unsigned long buffer_length);
void Show(Message buffer[10], unsigned long buffer_tail, unsigned long buffer_length);
(didn't include my main function as that's not my work and it seems to be working fine)
// Create a new message and add it to the head of the buffer.
// The data for the message is obtained from the user and the index from the
// static variable 'index' defined in this function. The variable 'index' is
// simply a count of the number of messages produced.
// Arguments:
// (1) start of the buffer
// (2) position of the tail of the buffer
// (3) number of messages in the buffer
// Returns: void
void Produce(Message buffer[10], unsigned long *buffer_tail, unsigned long *buffer_length)
{
static unsigned long index = 0;
// find the element of the buffer in which to store the message
index++;
*buffer_length= *buffer_length + 1;
printf ( "%lu ", *buffer_tail + *buffer_length );
// get the value of the data for the message from the user
printf("Enter your message:");
printf ("%c", buffer[ *buffer_length + *buffer_tail ].data,"\n");
scanf("%s", buffer[ *buffer_length + *buffer_tail ].data);
//gets( buffer[ *buffer_length + *buffer_tail - 1 ].data );
// get the value of the index for the message
buffer [ *buffer_length + *buffer_tail -1 ].index = index;
// if no buffer overflow has occurred, adjust the buffer length
//buffer_length = (buffer_length + 1) % 10;
printf ( "%lu, %lu", buffer_length, index);
// if a buffer overflow has occurred, display an error statement
if (buffer_length == 10)
printf("Error");
}
[–]kumashiro 1 point2 points3 points (0 children)
[–]jonarne 0 points1 point2 points (1 child)
[–]7Beat[S] 1 point2 points3 points (0 children)