在调用函数遇到的问题
在调用函数in_read的时候出现了问题,调试的时候发现程序执行到这个函数处就不执行了,in_write是向文件内写一个3*3矩阵和一个3*1的矩阵。in_read是读出这两个矩阵的行数和列数。把in_read单独执行下发现好使,真是不知道怎么回事了,麻烦大家解下疑惑。#include"stdio.h"
#include"stdlib.h"
#include"iostream.h"
#include"conio.h"
FILE *fp;
int **p1,**p2;
void in_write(FILE *fp);
int in_read(int h,int l,char w);
int main()
{
int ah=0,al=0,yh=0,yl=0;
char q;
fp=fopen("in_r.txt","w+"); /*write numbers to file in_r*/
printf("Please input the numbers.\n");
in_write(fp);
rewind(fp);
puts("The end to write.\n");
q='A';
printf("%c",q);
in_read(ah,al,q); /*read the matrix A*/
q='Y';
printf("%c",q);
in_read(yh,yl,q); /*read vector Y*/
return(0);
}
void in_write(FILE *fp) /*The function to write numbers*/
{
int i,j,m=0;
if(fp==NULL)
{
printf("open in_r error.\n");
exit(0);
}
else
{
printf("Now input the matrix a.\n");
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
scanf("%d ",&m);
fprintf(fp,"%d ",m);
}
fputc('\n',fp);
}
fflush(stdin);
printf("Then input vector Y\n");
fputc('\n',fp);
for(i=1;i<=3;i++)
{
scanf("%d ",&m);
fprintf(fp,"%d ",m);
fputc('\n',fp);
}
}
}
int in_read(int h,int l,char w) /*read the matrix*/
{
int m,d=0,flag=0,c=0,A=0;
h=0;
l=0;
char c1,c2;
for(;flag==0;)
{
fscanf(fp,"%d",&m);
fscanf(fp,"%c",&c1);
c++;
if(c1=='\n')
{
l=c;
h++;
if((h>1)&&c!=d)
{
A=1;
break;
}
fscanf(fp,"%c",&c2);
d=c;
c=0;
if(c2=='\n')
flag=1;
else
fseek(fp,-1l,1);
}
}
printf("In %c ah=%d,al=%d\n",w,h,l);
return(0);
}