3
Rebaz salimi 3840221821 09188888888
4
95120486525
95120482642
95120541325
95120860452
即时阅读它变成数组对象从struct books和struct MEMBERS并打印出的screen.here是我的代码:
struct books
{
long long int id;
char stname[20];
char name[20];
char Author[20];
int quantity;
float Price;
int count[100];
int code[100];
int rackno;
char *cat;
struct meroDate issued;
struct meroDate duedate;
};
struct MEMBERS
{
long long int code;
char Fname[40];
char Lname[40];
long long int Pnum;
float bedeh;
float credit;
struct meroDate issued;
struct meroDate duedate;
};
struct MEMBERS cur_member[100];
struct books cur_book[100];
int main()
{
getdataMEMBERS();
return 0;
}
int getdataMEMBERS()
{
FILE *myfile = fopen("Members.txt", "r");
FILE *myfile1 = fopen("Members.txt", "r");
if (myfile == NULL) {
printf("Cannot open file.\n");
return 1;
}
else {
char ch;
int count = 0;
do
{
ch = fgetc(myfile);
if (ch == '\n') count++;
} while (ch != EOF);
rewind(myfile);
//Since you put 2 earlier in the member.txt we need to dump it
//so that it wont affect the scanning process
int temp;
fscanf(myfile, "%d", &temp);
printf("%d\n", temp);
//Now scan all the line inside the text
int i;
for (i = 0; i < 1; i++) {
fscanf(myfile, "%s %s %lld %lld\n %d", cur_member[i].Fname,
cur_member[i].Lname, &cur_member[i].code, &cur_member[i].Pnum
,&cur_book[i].quantity);
printf("%s %s %lld %lld\n
%d\n",cur_member[i].Fname,cur_member[i].Lname,
cur_member[i].code,cur_member[i].Pnum , cur_book[i].quantity);
int j;
for(j=0;j
{
fscanf(myfile,"%d\n",&cur_book[j].id);
printf("%d\n",cur_book[j].id);
}
}
}
fclose(myfile);
}
一旦我printf这代码:
int j;
for(j=0;j
{
fscanf(myfile,"%d\n",&cur_book[j].id);
printf("%d\n",cur_book[j].id);
}
它给我:
631206013
631202130
631260813
631579940
应该想给我:
95120486525
95120482642
95120541325
95120860452
我已经改变了数据类型在struct bookslong long double id;但仍然gaves我这三个输出:
631206013
631202130
631260813
631579940
会有人知道在哪里问题可能是?数据类型还是别的?
2017-06-29
moh89
+1
有没有必要对这些数字进行计算?如果没有,只需存储*字符串*。 'double'不会使整数产生任何*意义,只会失去精度。为更广泛的'int'尝试'long long'。 –
+0
为什么'long long double'(它不是作为一个类型存在,你的意思是'long double'')而不是'long long int',它在支持的系统上至少有64位? –
+1
您正在用'%d'转换说明符打印(并扫描)一个'long long int'? –