Write a Decoder Function with Simple C Programming In a project I am working on,
ID: 657944 • Letter: W
Question
Write a Decoder Function with Simple C Programming
In a project I am working on, I have to read an input file with various logic gate commands and perform them on some given inputs. One of the commands I am able to receive is DECODER. My program needs to read the DECODER instruction line, with it's specified inputs and outputs and perform everything. Here is some more context for what I need help with:
I already have an AND and OR done, as well as a linkedlist to store my various inputs and outputs.
DECODER: This directive represents the decoder in logic design. The directive is followed by the number of inputs, names of the inputs, and the names of the outputs. The output are ordered in gray code sequence. An example decoder with two inputs A and B is specified as follows: DECODER 2ABPQRS P represents the A B output of the decoder. Q represents the A B output of the decoder, R represents the AB output of the decoder. S represents the AB output of the decoder. Note that the outputs of the decoder (i.e., P, Q, R, and S) are in gray code sequence.Explanation / Answer
#include <stdio.h>
void main()
{
FILE *fp;
char instr[100];
char c;
int arr[200];
int i=0;
fp = fopen("DECODEr.TXT","r");
do {
c = fscanf(fp,"%s",instr);
arr[i]=atoi(c);i++;
} while (c != EOF);
fclose(fp1);
switch(arr[0])
{case 2:
if((arr[1]==0)&&(arr[2]==0))
{arr[3]=0;
arr[4]=1; arr[6]=1; arr[6]=1; }
if((arr[1]==0)&&(arr[2]==1))
{arr[3]=1;
arr[4]=0; arr[6]=1; arr[6]=1; }
if((arr[1]==1)&&(arr[2]==0))
{arr[3]=1;
arr[4]=1; arr[6]=0; arr[6]=1; }
if((arr[1]==1)&&(arr[2]==1))
{arr[3]=1;
arr[4]=1; arr[6]=1; arr[6]=0; }
break;
case 3:
if((arr[1]==0)&&(arr[2]==0)&&(arr[3]==0))
{arr[4]=0;
arr[5]=1; arr[6]=1; arr[7]=1; arr[8]=1;
arr[9]=1; arr[10]=1; arr[11]=1; }
if((arr[1]==0)&&(arr[2]==0)&&(arr[3]==1))
{arr[4]=1;
arr[5]=0; arr[6]=1; arr[7]=1; arr[8]=1;
arr[9]=1; arr[10]=1; arr[11]=1; }
if((arr[1]==0)&&(arr[2]==1)&&(arr[3]==0))
{arr[4]=1;
arr[5]=1; arr[6]=0; arr[7]=1; arr[8]=1;
arr[9]=1; arr[10]=1; arr[11]=1; }
if((arr[1]==0)&&(arr[2]==1)&&(arr[3]==1))
{arr[4]=1;
arr[5]=1; arr[6]=1; arr[7]=0; arr[8]=1;
arr[9]=1; arr[10]=1; arr[11]=1; }
if((arr[1]==1)&&(arr[2]==0)&&(arr[3]==0))
{arr[4]=1;
arr[5]=1; arr[6]=1; arr[7]=1; arr[8]=0;
arr[9]=1; arr[10]=1; arr[11]=1; }
if((arr[1]==1)&&(arr[2]==0)&&(arr[3]==1))
{arr[4]=1;
arr[5]=1; arr[6]=1; arr[7]=1; arr[8]=1;
arr[9]=0; arr[10]=1; arr[11]=1; }
if((arr[1]==1)&&(arr[2]==1)&&(arr[3]==0))
{arr[4]=1;
arr[5]=1; arr[6]=1; arr[7]=1; arr[8]=1;
arr[9]=1; arr[10]=0; arr[11]=1; }
if((arr[1]==1)&&(arr[2]==1)&&(arr[3]==1))
{arr[4]=1;
arr[5]=1; arr[6]=1; arr[7]=1; arr[8]=1;
arr[9]=1; arr[10]=1; arr[11]=0; }
}printf(
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.