i need to modify the following code so that the parent thread can pass to the created thread a number (from 1 to 10) and the child thread should display that number of values. The number passed to each created thread can be a different one.
Note: In this case the number should be cast as void when being passed to pthread_create and cast back to integer within the thread.

how will i do this? can someone help me?

#include<stdio.h>

#include<pthread.h>



void * funct1(void * student);



main()

{

	char name[10];

	int studid[10];

	

	name[0] = "bob";

	name[1] = "bala";

	name[2] = "jim";	

	name[3] = "jean";

	name[4] = "paul";

	name[5] = "jack";

	name[6] = "smith";

	name[7] = "pierre";

	name[8] = "mala";

	name[9] = "sam";

	

	studid[0]= 1;

	studid[1]= 2;

	studid[2]= 3;

	studid[3]= 4;

	studid[4]= 5;

	studid[5]= 6;

	studid[6]= 7;

	studid[7]= 8;

	studid[8]= 9;

	studid[9]= 10;

	

	pthread_t threadid;

	

	pthread create(&threadid,NULL,funct1,(void*)name);

	pthread create(&threadid,NULL,funct2,(void*)studid);

	sleep(5);
	printf("Parent thread Exiting \n");

	

}

void *funct1(void*student)
{
	char stud=(void *)student;
	for (int i=0,i<10,i++)
	{
		printf("Name: %s", stud[i]);	
	}
	
}


void *funct2(void*student)
{
	char stud=(void *)student;
	for (int i=0,i<10,i++)
	{
		printf("Student ID: %s", stud[i]);	
	}
	
}

Wow, where to begin? First I would get rid of the idea of two arrays and combine them into one array of structures..Like so.

struct mys
{
  char * name;
  int studid;
};

struct mys thes[10];

Before we get into the nuts and bolts..In a C program the main function returns a integer..

int main()
{
return 0;
}

You stated in your posting

parent thread can pass to the created thread a number (from 1 to 10) and the child thread should display that number of values.

What exactly does that mean?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.