You have bit confused the functions.
pthread_create will create and run the thread. It will print the un-initialized buffer.
pthread_join suspends the main thread until the child-thread is executed.
So, you first need fgets() and then the pthread_create().
Or do this:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void *print(void* string)
{
pthread_mutex_lock(&mutex);
printf("%s\n", (char*)string);
pthread_mutex_unlock(&mutex);
}
int main(void)
{
char buffer[100];
pthread_t thread;
pthread_mutex_lock(&mutex);
pthread_create(&thread, NULL, print, (void*)buffer);
fgets(buffer, sizeof(buffer), stdin);
pthread_mutex_unlock(&mutex);
pthread_join(thread, NULL);
}