C语言的fprintf() 问题很严重..
请问高手为什么我用 fprintf(fp1,"%d ",bai[k][i]); 把二数组的值写到指定的文件
比如bai[1][1]=123 bai[1][2]=321 bai[1][3]=532...bai[1][n]=908,当数组值(比如321)个数少的时候可以写进文件,但当数组多的时候就出现乱码,,为什么??
我的代码如下:
#include "stdio.h"
#include "stdlib.h"
void main()
{
FILE *fp,*fp1,*fp2,*fp3;
int dan[500],dan1[20][500], bai[20][500],shi[20][500],ge[20][500],i=1,j=1,n,k=1,q=0;
/* FILE *fp4;
int t,a,c,dan11[500],gs1[20]={0},gs2[20]={0},b[100] , s[100], g[100],ch;
int Array[N];
int temp,temp1;
int index[N];
*/
if((fp=fopen("F:\\C++\\胆个数.txt","r"))==NULL)
{
printf("Can't open this file.\n");
exit(0);
}
while(!feof(fp))
{
fscanf(fp,"%d",&dan[i]);
if(i<101)
i++;
// dan[i]=getw(fp);
// i++;
}
n=i;
printf("%d\n ",n);
for(i=1;i<n;i++)
{
printf("%d ",dan[i]);
}
fclose(fp);
/*printf("%d\n",ar[0]);
printf("%d\n",ar[1]);
printf("%d\n",ar[2]);
*/
for(k=1;k<(n/(n/4)+1);k++) //把号分类
{
printf("\n");
j=1;
for(i=q+1;i<n;i=i+4)
{ dan1[k][j]=dan[i];
j++;
printf("%5d",dan1[k][j-1]);
}
q++;
}
for(k=1;k<(n/(n/4)+1);k++)
{
for(i=1;i<j;i++)
{
bai[k][i]=dan1[k][i]/100;
shi[k][i]=(dan1[k][i]%100)/10;
ge[k][i]=(dan1[k][i]%100)%10;
//printf("%3d",bai[k][i]);
printf("%d",bai[k][i]);
printf("%d",shi[k][i]);
printf("%d",ge[k][i]);
}
printf("\n");
}
for(k=1;k<(n/(n/4)+1);k++) //百位 十位 个位开始结合
{
if((fp1=fopen("F:\\C++\\B\\b.txt","w"))==NULL)
{
printf("Can't open this file.\n");
exit(0);
}
if((fp2=fopen("F:\\C++\\S\\s.txt","w"))==NULL)
{
printf("Can't open this file.\n");
exit(0);
}
if((fp3=fopen("F:\\C++\\G\\g.txt","w"))==NULL)
{
printf("Can't open this file.\n");
exit(0);
}
for(i=1;i<j;i++)
{
fprintf(fp1,"%d ",bai[k][i]);
fprintf(fp2,"%d ",shi[k][i]);
fprintf(fp3,"%d ",ge[k][i]);
// dan[i]=getw(fp);
// i++;
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
}
急急............