C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 4th, 2012, 05:59 PM
lisa92 lisa92 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 43 lisa92 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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];


}


Reply With Quote
  #2  
Old November 4th, 2012, 06:04 PM
jakotheshadows's Avatar
jakotheshadows jakotheshadows is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2009
Posts: 149 jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level)jakotheshadows User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 12 h 1 m 16 sec
Reputation Power: 35
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.

Reply With Quote
  #3  
Old November 4th, 2012, 06:31 PM
lisa92 lisa92 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 43 lisa92 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #4  
Old November 5th, 2012, 12:45 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,903 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 4 Days 7 m 35 sec
Reputation Power: 1774
But you didn't fix the necessary feedback.
See one of your other posts on the same subject
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Printing values in a column (truth table)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap