我有這個Members.txt
與此內容:如何在C語言中處理10位以上的小數點INT?
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<cur_book[i].quantity;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<cur_book[i].quantity;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 books
long long double id;
但仍然gaves我這三個輸出:
631206013
631202130
631260813
631579940
會有人知道在哪裏問題可能是?數據類型還是別的?
有沒有必要對這些數字進行計算?如果沒有,只需存儲*字符串*。 'double'不會使整數產生任何*意義,只會失去精度。爲更廣泛的'int'嘗試'long long'。 –
爲什麼'long long double'(它不是作爲一個類型存在,你的意思是'long double'')而不是'long long int',它在支持的系統上至少有64位? –
您正在用'%d'轉換說明符打印(並掃描)一個'long long int'? –