bài của mình nó bị lỗi này lúc bắt đầu chạy
các bạn giúp mình sửa lỗi này được không?
tối 11h phải nộp bài oy
phần code của mình đây:
include "stdio.h"
include "pthread.h"
include "stdlib.h"
struct arr{
int row,col;
int **a;
};
struct file{
struct arr a,b,c;
char* filename;
char* output;
};
void* nhapMaTran(void* ar){
struct file *fi = (struct file*) ar;
FILE *in;
in = fopen(fi->filename,"r");
//so hang cua ma tran A
fscanf(in,"%d",&fi->a.row);
//so cot cua ma tran A
fscanf(in,"%d",&fi->a.col);
fi->a.a = (int**)malloc(fi->a.row*sizeof(int *));
for(int i=0;i<fi->a.col;i++)
fi->a.a[i] = (int*)malloc(fi->a.col*sizeof(int));
for(int i=0;i<fi->a.row;i++)
for(int j=0;j<fi->a.col;j++)
fscanf(in,"%d",&fi->a.a[i][j]);
//so hang cua ma tran B
fscanf(in,"%d",&fi->b.row);
//so cot cua ma tran B
fscanf(in,"%d",&fi->b.col);
fi->b.a = (int**)malloc(fi->b.row*sizeof(int *));
for(int i=0;i<fi->b.col;i++)
fi->b.a[i] = (int*)malloc(fi->b.col*sizeof(int));
for(int i=0;i<fi->b.row;i++)
for(int j=0;j<fi->b.col;j++)
fscanf(in,"%d",&fi->b.a[i][j]);
fclose(in);
}
void* nhanMaTran(void* ar){
struct file *fi = (struct file*) ar;
fi->c.row = fi->b.row;
fi->c.col = fi->a.col;
fi->c.a = (int**)malloc(fi->c.row*sizeof(int*));
for(int i=0;i<fi->c.col;i++)
fi->c.a[i] = (int*)malloc(fi->c.col*sizeof(int));
for(int i=0;i<fi->c.row;i++)
for(int k=0;k<fi->c.col;k++){
fi->c.a[i][k] = 0;
for(int j=0;j<fi->a.row;j++)
fi->c.a[i][k] += fi->a.a[i][j]*fi->b.a[j][k];
}
}
void* ketQua(void* ar){
struct file *fi = (struct file*) ar;
FILE *out;
out = fopen(fi->output,"wb");
for(int i=0;i<fi->c.row;i++){
for(int j=0;j<fi->c.col;j++){
fprintf(out,"%d",fi->c.a[i][j]);
fprintf(out," ");
}
fprintf(out,"\n");
}
fprintf(out,"\n");
fclose(out);
}
int main(int argc,char* argv[]){
pthread_t tid[3];
struct file fi;
int status,*pstatus = &status;
fi.filename = argv[1];
pthread_create(&tid[0],NULL,nhapMaTran,(void*) &fi);
sleep(1);
if(pthread_join(tid[0],(void**) pstatus)==0){
int tmp = pthread_create(&tid[1],NULL,nhanMaTran,(void*) &fi);
if(tmp==0 && pthread_join(tid[1],(void**) pstatus)==0){
fi.output = argv[2];
pthread_create(&tid[2],NULL,ketQua,(void*) &fi);
}
}
sleep(2);
}