If no one one is eating initially and they both excute the function take_ forks the first one will run test and see that neither person to his left or right meets the test so he will change his state...
Type: Posts; User: jalex39
If no one one is eating initially and they both excute the function take_ forks the first one will run test and see that neither person to his left or right meets the test so he will change his state...
# define N 5
# define LEFT (i+N-1)%N
# define RIGHT (i+1)%N
# define THINKING 0
# define HUNGRY 1
# define EATING 2
typede int semaphore;
int state[N];
semaphore mutex = 1;
semaphore...
I am going to put this algorithm (attachment) in my code and however this code supposbly works and but it seems to me you could have a race condition if two adjacent philosophers try to aquire forks...
I understand my code works. That isn't the problem. I guess I was just wondering why with my code does the reader still have access when the writter is writing sometimes it will say # of readers 1....
I am working on writting 2 programs, the first was using the algorithm provided to me which basically blocks the writter out as long as there are readers. That wasn't much of a problem. I then...
Here is my new code:
#include <stdio.h>
typedef struct {
int avg_high_temp;
int avg_low_temp;
float avg_precip;
int avg_wind_speed;
} weather_t;
fgetc is a way to input a character at a time but the problem is the data is 3 ints and 1 float so how do I get mixed data in? I see that fread is for binary only- my mistake
I am writting a prohram that declares a struct with 3 ints and 1 float called weather_t. I must read the data in from a txt file for 12 months of data which would be 48 numbers. I need 2 functions...
If I am reading an array from a pointer, how can I get the first element of array: Right now the following code gets me reading an array of 500 intergers 100 at a time. What if I want to make the...
Works great
int findmax(int array[], int size)
{
int max = 0;
int i;
for (i = 0; i < size; ++i)
if (max > array[max])
max = i;
return max;
When I run those # its backwards but if I use 1 3 5 it works
I am writting a program that you enter intergers and am using a find minimum and max functions however I seem to be having a problem when I mix positive and negative # or use a zero. I think I am...
Got it right anyways thanks. Got my outer loop mixed with inner and got the function call correct.
I have used this board once before and it was very helpful especially when I was blinded by the obvious so I thought I would ask to see if I have my loops back wards or incorrect. I am trying to...
I'll tell you sometimes you can understand the hardest part of something whether it be programing like this or anything in life but what seems to be the simpliest you can rack your brains. I...
I am new to c and I am buliding a program with a buch of nested if and a switch statement based on my an input of a character from a scanf statement. the problem is when you ask the question what...