Pointers not working

So I have a C program for my homework where I have to update a some values using a truth table. Here is the code for it.

The problem is that when I update the values on line 71-73 and print them I get one number then in the main method on line 36 I get a different number. The number can only be 0 or 1 but it is not constant.

What am I doing wrong in the code?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

/* note to the grader
 * I mixed up Q1 and Q3. My Q0 actually refers to Q2 from the question and vice versa
*/
#include <stdio.h>
#include <time.h>

/****************************************************************************
 *                                                                          *
 * Function: main                                                           *
 *                                                                          *
 * Purpose : Main entry point.                                              *
 *                                                                          *                                    
 *                                                                          *
 ****************************************************************************/

// implements state machine
// given input m
void MyStateMachine (char M, char *Q2, char *Q1, char *Q0);
int atoi(const char *string);

int main(int argc, char *argv[])
{
	// declare outputs
	char Q0 = 1;
	char Q1 = 0;
	char Q2 = 0;
 	

	char M = 1;
	
	

	MyStateMachine(M,&Q0,&Q1,&Q2);
	
	printf("%d",Q2);
	

    return 0;
}

void MyStateMachine (char M, char *Q2, char *Q1, char *Q0)
{
	// declare current state varibles (T)
	int q0 = *Q0;
	int q1 = *Q1;
	int q2 = *Q2;
	int m = M;

	// declare next state varibles (t+T)
	int q0t = 0;
	int q1t = 0;
	int q2t = 0;
	

	// get next state
	q0t =   (m & !q1 & !q2 &  q0) |
			(m & !q1 &  q2 &  q0) |
			(m &  q1 & !q2 & !q0) |
			(m &  q1 & !q2 &  q0) ;
			
	q1t =   (!q2 & !q0  & !m &  q1)  |
			(!q2 &  q0  &  m &  q1)  |
			( q2 & !q0  & !m & !q1)  |
			( q2 &  q0  &  m & !q1)  ;

	q2t =   ( m &  q0 & !q2) |
		 	(!m & !q0 & !q2) ;

	//set the state
	*Q0 = q0t;
	*Q1 = q1t;
	*Q2 = q2t; 

	printf("%d",q2t);
	printf("%d",*Q2);
	
}
Q2 is pointed to by Q0 in MyStateMachine.
Topic archived. No new replies allowed.