'Compiler says variable is undeclared even though it is declared

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 "initialzer element not constant". 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

#include <stdio.h>
#include <stdlib.h>

char *text1 = "This is a string.";
char *text2 = "Yet another thing.";
int *count = 0;


void printlist(const int* lst){
  printf("ASCII codes and corresponding characters.\n");
  while(*lst != 0){
    printf("0x%03X '%c' ", *lst, (char)*lst);
    lst++;
  }
  printf("\n");
}

void endian_proof(const char* c){
  printf("\nEndian experiment: 0x%02x,0x%02x,0x%02x,0x%02x\n",
         (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(&text1, &list1, &count);
}

int main(void){
  int *list1 = (int *)(malloc(80));
  int *list2 = (int *)(malloc(80));
  work();

  printf("\nlist1: ");
  printlist(list1);
  printf("\nlist2: ");
  printlist(list2);
  printf("\nCount = %d\n", count);

  endian_proof((char*) &count);
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source