Cの関数ポインタとスレッドについて学習しています。次のコードは、ユーザーから文字列を読み取るスレッドを作成します。次に、ユーザーがメインスレッドに入力した名前を出力します。しかし、セグメンテーション違反が発生しました:11
#include<pthread.h>
#include<stdio.h>
int agelimit;
char *string1, *string2;
void *getName();
//void (*getAge)();
main(){
pthread_t thread1,thread2;
string1 = malloc(1000);
//scanf("%s",string0);
pthread_create(&thread1, 0, getName, 0);
//pthread_create(&thread2, 0, getAge, 0);
sleep(10);
printf("name is %s age is",string1);
}
void *getName(){
int x;
printf("enter name:");
scanf("%s",&string1);
}