Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     //declaring variables for data storage
  7.     float   input_gates;
  8.     float   input_nodes;
  9.     char    input_words[128][128];
  10.     float   input_numbers[128][128];
  11.  
  12.     //reading from file
  13.     //change the file location here
  14.     FILE *TEXTFILE;
  15.     TEXTFILE = fopen("C:\\data.txt","r");
  16.    
  17.     fscanf(TEXTFILE,"%f",&input_gates);
  18.     fscanf(TEXTFILE,"%f",&input_nodes);
  19.  
  20.     for(int b = 0; b < input_gates; b++)
  21.     {
  22.         fscanf(TEXTFILE,"%s",&input_words[b]);
  23.  
  24.         for(int a = 1; a < 100; a++)
  25.         {
  26.             fscanf(TEXTFILE,"%f",&input_numbers[a][b]);
  27.            
  28.             if ( input_numbers[a][b] == 0 )
  29.             {
  30.                 break;
  31.             }
  32.         }
  33.     }
  34.    
  35.     fclose(TEXTFILE);
  36.  
  37.     //converting text to assigned numbers
  38.     //modify them how you see fit
  39.     //assigned values will go into column 0
  40.  
  41.     for(int b = 0; b < input_gates; b++)
  42.     {  
  43.         if ( strcmp ( input_words[b],"AND" ) == 0 )
  44.         {   input_numbers[0][b] = 1;    }
  45.  
  46.         if ( strcmp ( input_words[b],"OR" ) == 0 )
  47.         {   input_numbers[0][b] = 2;    }
  48.  
  49.         if ( strcmp ( input_words[b],"NOT" ) == 0 )
  50.         {   input_numbers[0][b] = 3;    }
  51.  
  52.         if ( strcmp ( input_words[b],"XOR" ) == 0 )
  53.         {   input_numbers[0][b] = 4;    }
  54.  
  55.         if ( strcmp ( input_words[b],"XAND" ) == 0 )
  56.         {   input_numbers[0][b] = 5;    }
  57.  
  58.         if ( strcmp ( input_words[b],"NOR" ) == 0 )
  59.         {   input_numbers[0][b] = 6;    }
  60.  
  61.         if ( strcmp ( input_words[b],"NAND" ) == 0 )
  62.         {   input_numbers[0][b] = 7;    }
  63.     }
  64.  
  65.     //printing the data we now have onto the screen
  66.     //will have the same visual format as the .txt file
  67.  
  68.     //change printf("%f\t%f\n",input_gates,input_nodes); to show all decimal places
  69.     //change printf("%.0f\t%.0f\n",input_gates,input_nodes); to show 0 decimal places
  70.     printf("%f\t%f\n",input_gates,input_nodes);
  71.  
  72.     for(int b = 0; b < input_gates; b++)
  73.     {
  74.         printf("%s\t",input_words[b]);
  75.  
  76.         //int a = 0 ~~~ will show the gate assigend numbers
  77.         //int a = 1 ~~~ will hide the gate assigned numbers
  78.         for(int a = 0; a < 100; a++)
  79.         {
  80.             //change printf("%f\t",input_numbers[a][b]); to show all decimal places
  81.             //change printf("%.0f\t",input_numbers[a][b]); to show 0 decimal places
  82.             printf("%f\t",input_numbers[a][b]);
  83.  
  84.             if(input_numbers[a][b] == 0)
  85.             {
  86.                 printf("\n");
  87.                 break;
  88.             }
  89.         }
  90.     }
  91.  
  92.     return (0);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement