C语言 将文件中的数字输入到一个二维数组中为什么输出的结果不对???
#include<stdio.h>#include<stdlib.h>#include<string.h>intmain(){FILE*fq;FILE*fv;fq=fop...
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
FILE*fq;
FILE*fv;
fq = fopen("message.dat", "at");
fv = fopen("rank1.dat", "w");
int h, g;
char idcard[30];
printf("\n请输入您的登录id:");
fflush(stdin);
gets(idcard);
int i, j, m, n, q, c, d;
printf("请选择租用的场地号(1-4)\n");
scanf("%d", &m);
printf("\n请选择时间段:\n1.6:00-8:00\n2.8:00-10:00\n3.10:00-12:00\n4.12:00-14:00\n5.14:00-16:00\n6.16:00-18:00\n7.18:00-20:00\n8.20:00-22:00\n");
scanf("%d", &n);
char sys[4][8];
for (g = 0; g < 4; g++)
{
for (h = 0; h < 8; h++)
{
fscanf(fv, "%d,", sys[h][g]); //将信息写入一个二维数组,将指定项改为32//
}
}
sys[m - 1][n - 1] = (32);
printf(" am: 6-8 8-10 10-12 pm: 12-14 14-16 16-18 18-20 20-22\n");
for (i = 0; i <= 3; i++) //输出数组//
{
printf("room.%d",i+1);
for (j = 0; j <= 7; j++)
{
printf("%9c", sys[i][j]);
}
printf("\n");
} //输出数组//*/
printf("\n$为未租用场地, 代表以租用场地");
printf("\n您的id为:");
puts(idcard);
printf("您租用的场地为%d号场地,您租用的时段为%d:00-%d:00\n", m,n*2+4,n*2+6 );
struct member_in
{
char name[30];
int room;
int time;
int sport;
}list;
strcpy(list.name, idcard);
list.room = m;
list.time = n;
list.sport =1;
fprintf(fq, "%s %d %d %d", list.name,list.room,list.time,list.sport); //存入用户租用信息//
fclose(fq);
int v, x;
for (x = 0; x<4; x++)
{
for (v= 0; v<8; v++)
{
fprintf(fv, "%d", sys[x][v]);
}
}
fclose(fv);
system("pause");
return 0;
}
文件中的数字为36,36,36,36,36,36,36,36,36,32,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36
输出的数组中应该为$,但程序中显示?而且文件中的数字也全变成-52了。。。。。 展开
#include<stdlib.h>
#include<string.h>
int main()
{
FILE*fq;
FILE*fv;
fq = fopen("message.dat", "at");
fv = fopen("rank1.dat", "w");
int h, g;
char idcard[30];
printf("\n请输入您的登录id:");
fflush(stdin);
gets(idcard);
int i, j, m, n, q, c, d;
printf("请选择租用的场地号(1-4)\n");
scanf("%d", &m);
printf("\n请选择时间段:\n1.6:00-8:00\n2.8:00-10:00\n3.10:00-12:00\n4.12:00-14:00\n5.14:00-16:00\n6.16:00-18:00\n7.18:00-20:00\n8.20:00-22:00\n");
scanf("%d", &n);
char sys[4][8];
for (g = 0; g < 4; g++)
{
for (h = 0; h < 8; h++)
{
fscanf(fv, "%d,", sys[h][g]); //将信息写入一个二维数组,将指定项改为32//
}
}
sys[m - 1][n - 1] = (32);
printf(" am: 6-8 8-10 10-12 pm: 12-14 14-16 16-18 18-20 20-22\n");
for (i = 0; i <= 3; i++) //输出数组//
{
printf("room.%d",i+1);
for (j = 0; j <= 7; j++)
{
printf("%9c", sys[i][j]);
}
printf("\n");
} //输出数组//*/
printf("\n$为未租用场地, 代表以租用场地");
printf("\n您的id为:");
puts(idcard);
printf("您租用的场地为%d号场地,您租用的时段为%d:00-%d:00\n", m,n*2+4,n*2+6 );
struct member_in
{
char name[30];
int room;
int time;
int sport;
}list;
strcpy(list.name, idcard);
list.room = m;
list.time = n;
list.sport =1;
fprintf(fq, "%s %d %d %d", list.name,list.room,list.time,list.sport); //存入用户租用信息//
fclose(fq);
int v, x;
for (x = 0; x<4; x++)
{
for (v= 0; v<8; v++)
{
fprintf(fv, "%d", sys[x][v]);
}
}
fclose(fv);
system("pause");
return 0;
}
文件中的数字为36,36,36,36,36,36,36,36,36,32,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,36
输出的数组中应该为$,但程序中显示?而且文件中的数字也全变成-52了。。。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询