大家帮忙看看,为什么两个Printf("%f\n",pArray[i][j])的值不一样?
/* Guass xiaoyuan method */
#include <stdio.h>
#include <mem.h>
#include <stdlib.h>
void main(){
int rows = 1,
cols = 1;
int cur = 0;
int i,j;
char abstr[1024] = {0};
char *p = NULL;
float **pArray = NULL; /* buffer for element */
clrscr(); /*clear the screen*/
printf("please input the matrix A for equations:\n");
printf("input style:[1 1 1;2 2 2;3 3 3]\n");
printf("A=");
gets(abstr); /*if use printf,the blank wll be omitted*/
/* to calculate how many rows and cols*/
p=abstr;
p=strchr(p,';');
while(p){
rows++;
p=p+1;
p=strchr(p,';');
}
for(cur = 0 ; abstr[cur] != ';' ;cur++)
if (abstr[cur]==' ') cols++;
/* xiaoyuan */
pArray=(float**)malloc(sizeof(float)*rows*cols);
p=abstr+1;
for(i = 0; i < rows; i++)
for(j = 0; j <cols; j++){
pArray[i][j] = (float)atof(p);
p++;
while(((*p) != ' ') && ((*p) !=';')) p++;
p++;
printf("%f\n",pArray[i][j]);
}
for(i=0; i < rows; i++){
for(j=0; j <cols; j++)
printf("%f ",pArray[i][j]);
printf("\n");
}
}
如题,谢了