当前位置: 技术问答>linux和unix
Unix 下C语言编程的问题 Segmentation fault
来源: 互联网 发布时间:2017-04-26
本文导语: 调试已经通过,但是在UNIX中运行a.out文件的时候会报出segmentation fault #include #include #include void* CaculateLine(void *lines); void OutMatrix(int* matrix,int row,int column); int GetMatrix(char *filename); int GetNextValue(FILE *file); //define m...
调试已经通过,但是在UNIX中运行a.out文件的时候会报出segmentation fault
#include
#include
#include
void* CaculateLine(void *lines);
void OutMatrix(int* matrix,int row,int column);
int GetMatrix(char *filename);
int GetNextValue(FILE *file);
//define matrix A and B
int A_Row, A_Column,B_Row, B_Column;
int* A,*B;
//define matrix C
int C_Row,C_Column;
int* C;
int main()
{
//define threads
pthread_t * pthreads;
int i=0;
//read matrixes A and B
GetMatrix("C:\matrix.txt");
//out the matrix
printf("Set 1 Matrix A:n");
OutMatrix(A,A_Row,A_Column);
printf("nSet 2 Matrix B:n");
OutMatrix(B,B_Row,B_Column);
//initialize matrix C
C_Row=A_Row;
C_Column=B_Column;
C=(int*)malloc(sizeof(int)*C_Row*C_Column);
//initialize threads
{
int* args=(int*)malloc(sizeof(int)*A_Row);//store the arg of the function :CaculateLine
pthreads=(pthread_t*)malloc(sizeof(pthread_t)*A_Row);
printf("n");
for(i=0;i