I have to create two threads. Then one thread will take input by using scanf function and then another thread will print the input value. How to do that. My following program is giving segmentation fault.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<unistd.h>
void *scan(void *s)
{
int *s1=(int *)s;
scanf("%d",s1);
pthread_exit((void *)s1);
}
void *print(void *s)
{
int *s1=(int *)s;
printf("%d",(*s1));
}
int main()
{
pthread_t tid1,tid2;
int *s;
pthread_create(&tid1,NULL,scan,NULL);
pthread_join(tid1,(void **)&s);
sleep(5);
pthread_create(&tid2,NULL,print,(void *)s);
pthread_join(tid2,NULL);
return 0;
}