title: print the value of variables while running in C
body: <p>I am trying to test some packages written in C by checking the value of the local and global variables, I tried to use the GDB debugger and fprint as suggested by many people here and they worked well with simple and small programs, but with the package, it's not easy.</p>
  
  <p>So, I need to extract all variables into a txt.file (each line has one variable) and then while running the program I need to print the value of these variables.</p>
  
  <p>I used a normal print statement to take the name of variables from txt file, the problem is the exact character is printed.</p>
  
  <p><strong>Question</strong>: how do I use these characters from the text file as variables to print the values not the name?</p>
  
  <p>variables.txt</p>
  
  <pre><code>x
  y
  d
  </code></pre>
  
  <p>main.c</p>
  
  <p>in the main file, I included the header and called the func.</p>
  
  <pre><code>//printState.h
  void printstate(){
  
      char ch;
      FILE *fp;
      if(fp = fopen("Varaibles.txt", "r"))
      {       
          ch=getc(fp);
          while(ch != EOF)
          {
              printf("%c",ch);
              ch = getc(fp);
          }
          fclose(fp);
      }
  }
  
  int func(int x) {
      int y = 0;
      x = y + x;
  
      if(x &gt; 0){
          x = x % 4;
          printstate();
          /* I want to know the value of x at this point.*/
      }
      else {
          x = x + 1;
          printstate();
          /* I want to know the value of x at this point.*/
      }
      return x;
  }
  </code></pre>
  
  <p>expected output:
  is the value of x, y, d after the statement <code>(x = x % 4)</code> and <code>(x = x + 1)</code>
  For example:</p>
  
  <pre><code>5
  7
  6
  </code></pre>
  
  <p>the actual output I got was: </p>
  
  <pre><code>x
  y
  d
  </code></pre>