The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Printing values in a column (truth table)
Discuss Printing values in a column (truth table) in the C Programming forum on Dev Shed. Printing values in a column (truth table) C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 4th, 2012, 05:59 PM
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 43
Time spent in forums: 10 h 31 m 45 sec
Reputation Power: 2
|
|
|
Printing values in a column (truth table)
I should have 5 columns for R, I0, I1, Out0, Out1 respectively.
Instead I have 8 columns and I dont understand where it is coming from..
Code:
#include <stdio.h>
void fsm1(char Reset,char I0, char I1, char *Out0, char *Out1);
void fsm2(char Reset,char I0, char I1, char *Out0, char *Out1);
int main(int argc, char *argv[])
{
char I1,I0,Reset, Out1, Out0, i;
printf("PIC Microcontroller\n\n");
printf("Operations with Reset=0\n\n");
printf("R I0 I1 Out0 Out1\n\n");
Reset=0;
I0=0;
I1=0;
Out0=0;
Out1=0;
for(i=0;i<17;i++)
{
printf("%1d %1d %1d %1d %1d", Reset, I0, I1, Out0, Out1);
fsm1(Reset,I0,I1,&Out0,&Out1);
printf("%1d %1d %1d %1d \n",I0,I1,Out0,Out1);
}
printf("\n\n Operation with R=1\n\n");
printf("R I0 I1 Out0 Out1\n\n");
Reset=1;
I0=0;
I1=0;
Out0=0;
Out1=0;
int j;
for(j=0;j<17;j++)
{
printf("%1d %1d %1d %1d %1d", Reset, I0, I1, Out0, Out1);
fsm2(Reset,I0,I1,&Out0,&Out1);
printf("%1d %1d %1d %1d \n",I0,I1,Out0,Out1);
}
printf("\n\n\n");
}
void fsm1(char Reset,char I0, char I1, char *Out0, char *Out1)
{
static char I0table[] = {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1};
static char I1table[] = {0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1};
static char Out0table[] = {1,1,1,1,0,1,0,1,1,0,1,0,0,0,0,0};
static char Out1table[] = {0,1,0,1,0,0,1,1,1,0,1,0,1,0,1,0};
int index=(I0<<2)+(I1<<1)+(*Out0<<0)+*Out1;
I0=I0table[index];
I1=I1table[index];
*Out0=Out0table[index];
*Out1=Out1table[index];
}
void fsm2(char Reset,char I0, char I1, char *Out0, char *Out1)
{
static char I0table[] = {0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1};
static char I1table[] = {0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1};
static char Out0table[] = {1,1,1,1,0,1,0,1,1,0,1,0,0,0,0,0};
static char Out1table[] = {0,1,0,1,0,0,1,1,1,0,1,0,1,0,1,0};
int index=(I0<<2)+(I1<<1)+(*Out0<<0)+*Out1;
I0=I0table[index];
I1=I1table[index];
*Out0=Out0table[index];
*Out1=Out1table[index];
}
|

November 4th, 2012, 06:04 PM
|
 |
Contributing User
|
|
|
|
|
shouldn't you have a \n in your first printf? Otherwise the output from your 2nd printf will probably start on the same line making it look like you have more columns.
|

November 4th, 2012, 06:31 PM
|
|
Contributing User
|
|
Join Date: Oct 2011
Posts: 43
Time spent in forums: 10 h 31 m 45 sec
Reputation Power: 2
|
|
Quote: | Originally Posted by jakotheshadows shouldn't you have a \n in your first printf? Otherwise the output from your 2nd printf will probably start on the same line making it look like you have more columns. |
Yeah now I have 5 columns but my values are messed up...
|

November 5th, 2012, 12:45 AM
|
 |
Contributed User
|
|
|
|
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|