Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- //declaring variables for data storage
- float input_gates;
- float input_nodes;
- char input_words[128][128];
- float input_numbers[128][128];
- //reading from file
- //change the file location here
- FILE *TEXTFILE;
- TEXTFILE = fopen("C:\\data.txt","r");
- fscanf(TEXTFILE,"%f",&input_gates);
- fscanf(TEXTFILE,"%f",&input_nodes);
- for(int b = 0; b < input_gates; b++)
- {
- fscanf(TEXTFILE,"%s",&input_words[b]);
- for(int a = 1; a < 100; a++)
- {
- fscanf(TEXTFILE,"%f",&input_numbers[a][b]);
- if ( input_numbers[a][b] == 0 )
- {
- break;
- }
- }
- }
- fclose(TEXTFILE);
- //converting text to assigned numbers
- //modify them how you see fit
- //assigned values will go into column 0
- for(int b = 0; b < input_gates; b++)
- {
- if ( strcmp ( input_words[b],"AND" ) == 0 )
- { input_numbers[0][b] = 1; }
- if ( strcmp ( input_words[b],"OR" ) == 0 )
- { input_numbers[0][b] = 2; }
- if ( strcmp ( input_words[b],"NOT" ) == 0 )
- { input_numbers[0][b] = 3; }
- if ( strcmp ( input_words[b],"XOR" ) == 0 )
- { input_numbers[0][b] = 4; }
- if ( strcmp ( input_words[b],"XAND" ) == 0 )
- { input_numbers[0][b] = 5; }
- if ( strcmp ( input_words[b],"NOR" ) == 0 )
- { input_numbers[0][b] = 6; }
- if ( strcmp ( input_words[b],"NAND" ) == 0 )
- { input_numbers[0][b] = 7; }
- }
- //printing the data we now have onto the screen
- //will have the same visual format as the .txt file
- //change printf("%f\t%f\n",input_gates,input_nodes); to show all decimal places
- //change printf("%.0f\t%.0f\n",input_gates,input_nodes); to show 0 decimal places
- printf("%f\t%f\n",input_gates,input_nodes);
- for(int b = 0; b < input_gates; b++)
- {
- printf("%s\t",input_words[b]);
- //int a = 0 ~~~ will show the gate assigend numbers
- //int a = 1 ~~~ will hide the gate assigned numbers
- for(int a = 0; a < 100; a++)
- {
- //change printf("%f\t",input_numbers[a][b]); to show all decimal places
- //change printf("%.0f\t",input_numbers[a][b]); to show 0 decimal places
- printf("%f\t",input_numbers[a][b]);
- if(input_numbers[a][b] == 0)
- {
- printf("\n");
- break;
- }
- }
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement