How to access argv[x] from another function other than main???

Hi friends,
when I am passing arguments to main, I want another function to be able to have access to that function, the problem is that I am creating athread, which has a function like void *xyz(void *), how can pass the refernce of argv[x] to this function, if you see my program, you will better see the problem, so here it is!

 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <pthread.h>
 
int main(int argc, char *argv[])
{
        void *thread1(void *);
        void *thread2(void *);
        if(argc != 2)
        {
        printf("Invalid no. of arguments!\n");
        exit(-1);
        }
        else
        {
        pthread_t tid1;
        pthread_t tid2;
        int t1 = 1;
        int t2 = 2;
        pthread_attr_t attr1;
        pthread_attr_t attr2;
        pthread_attr_init(&attr1);
        pthread_attr_init(&attr2);
        {
        pthread_create(&tid1,&attr1,thread1,(void *)t1);
        pthread_create(&tid2,&attr2,thread2,(void *)t2);
        }
        {
        pthread_join(tid1,NULL);
        pthread_join(tid2,NULL);
        }
        printf("\nThreads finished!\n");
        }
        return 0;
}
void *thread1(void *n)
{
        while(1)
        {
        printf("%s\n\n",argv[1]);
        sleep(1);
        }
        pthread_exit(0);
}
void *thread2(void *n)
{
        while(1)
        {
        printf("%s\n\n",argv[2]);
        sleep(1);
        }
        pthread_exit(0);
}
 

I this program the two thread functions don't have access to arv, what should I do???

Thanks

In this case I generally create a data structure that has all of the information that needs to be passed to the thread and pass it in. The value of argv and argc would be included in the struct.

The easy way is to create two global variables

char **gargv;
int gargc;

You then can assign argv and argc to them, and reference them in your threads. I'm not a big fan of globals, but this works.

globals shouldn't be used for things which aren't global, but argc/argv look pretty global to me -- outside values which belong to the whole program. I see nothing wrong with it.