Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- typedef struct data
- {
- int value;
- struct data * next;
- } Data;
- typedef Data * DataList;
- typedef int (*CallBack)(DataList);
- int * decToBinary(int n)
- {
- int * binaryNum = calloc(14, sizeof(int));
- int i = 0;
- while (n > 0) {
- binaryNum[i] = n % 2;
- n = n / 2;
- i++;
- }
- return binaryNum;
- }
- Data * createData(int value)
- {
- Data * dataptr;
- dataptr = malloc(sizeof(Data));
- dataptr -> value = value;
- dataptr -> next = NULL;
- return dataptr;
- }
- void appendData(DataList *lstptr, Data * newptr)
- {
- if (*lstptr == NULL)
- {
- *lstptr = newptr;
- return;
- }
- appendData(&((*lstptr)->next), newptr);
- return;
- }
- int main(){
- int vars, i, j, fr;
- DataList bit_list = NULL;
- int * temp = malloc (sizeof(int) * vars);
- printf("Please insert the number of inputs: ");
- scanf("%d", &vars);
- printf("Please insert the step (pulse length): ");
- scanf("%d", &fr);
- printf("\tbegin\n");
- for(i=0;i<pow(2, vars);i++)
- {
- temp = decToBinary (i);
- if (i!=0)
- {
- printf("#%d\t", fr);
- }
- else printf("\t");
- printf("\tInA=%d;\t", temp[vars-1]);
- bit_list = createData (temp[vars-1]);
- for (j=vars-2; j>=0; j--)
- {
- printf("In%c=%d;\t", (64 + vars - j), temp[j]);
- appendData (&bit_list, createData(temp[j]));
- }
- putchar('\n');
- }
- printf("#%d\t$stop;\nend", fr);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment