hi,
following is the code in which i have created two threads and two these two threads i have passed one structure.
for the second thread, in the threadfunction, it shows the value fo charatcer and count as empty !!
any idea what i am doing wrong?
thanx
deepak
#include<stdio.h>
#include<pthread.h>
struct str1
{
char character;
int count;
};
void* threadfunction(void* param)
{
struct str1* p = (struct str1*)param;
int i;
printf("the character to be printed is %c and the number of time is %d\n\n",p->character, p->count);
for(i = 0; i< p->count; i++)
printf("%c",p->character);
return NULL;
}
int main()
{
pthread_t thread1_id;
pthread_t thread2_id;
struct str1 structthread1;
struct str1 structthread2;
structthread1.character='D';
structthread1.count=5;
pthread_create(&thread1_id, NULL, &threadfunction, &structthread1);
structthread2.character='S';
structthread2.count=7;
// printf("the character to be printed is %c and the number of time is %d\n\n",structthread1.character,structthread1.coun t);
// printf("the character to be printed is %c and the number of time is %d\n\n",structthread2.character, structthread2.count);
//pthread_create(&thread1_id, NULL, &threadfunction, &structthread1);
pthread_create(&thread2_id, NULL, &threadfunction, &structthread2);
return 0;
}