title: Compiler says variable is undeclared even though it is declared
body: <p>when i try to run this code i get the error: error: 'list1' undeclared (first use in this function). But i have declared the variable in main(), I also tried declaring it at the top, under text1,text2 and count. But then it said &quot;initialzer element not constant&quot;. I've tried googling it but with no luck. btw the code isn't finished yet but i cant get past this error and just want to fix it.
  Thank you</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  char *text1 = &quot;This is a string.&quot;;
  char *text2 = &quot;Yet another thing.&quot;;
  int *count = 0;
  
  
  void printlist(const int* lst){
    printf(&quot;ASCII codes and corresponding characters.\n&quot;);
    while(*lst != 0){
      printf(&quot;0x%03X '%c' &quot;, *lst, (char)*lst);
      lst++;
    }
    printf(&quot;\n&quot;);
  }
  
  void endian_proof(const char* c){
    printf(&quot;\nEndian experiment: 0x%02x,0x%02x,0x%02x,0x%02x\n&quot;,
           (int)*c,(int)*(c+1), (int)*(c+2), (int)*(c+3));
  
  }
  
  void copycodes(char *text, int *list, int *counter){
      while(*text != 0){
          *list = *text;
          list++;
          text++;
      }
  }
  
  void work(){
      copycodes(&amp;text1, &amp;list1, &amp;count);
  }
  
  int main(void){
    int *list1 = (int *)(malloc(80));
    int *list2 = (int *)(malloc(80));
    work();
  
    printf(&quot;\nlist1: &quot;);
    printlist(list1);
    printf(&quot;\nlist2: &quot;);
    printlist(list2);
    printf(&quot;\nCount = %d\n&quot;, count);
  
    endian_proof((char*) &amp;count);
  }
  </code></pre>