怎么了?我不能添加...... [英] What is wrong? I can't add...

查看:80
本文介绍了怎么了?我不能添加......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ok这是一个问题,我有一个虚构的数据库程序,我需要

代码,添加一个我有函数inser_patient的病人。但是当我想要输入详细信息时,我不会按照我想要的方式工作。


代码:


#include< stdio.h>

#include< stdlib.h>

#include< time.h>

#include< string.h>


#define MAXPATIENTS 20

struct details {

int id;

char forename [20];

char initial;

char surname [20];

int day_of_entry;

int max_wait;

};


struct details患者[MAXPATIENTS];

int npatients = 0;


int insert_patient(int index,struct details newpatient);


int main(void){

int选择;

int id;

int loop = 1;

int n = 0;

int error = 0;

int limit;

int Qnum;


FILE * fptr; //将文件指针声明为fptr

fptr = fopen(" queue.dat"," r"); //打开queue.dat到fptr

//读取

while(fscanf(fptr,"%d%s%c%s%d%d [^ \\ \\ n \\ n \\ n \\ n \\ n \\ n \\ n&n;& \\ n \\ n患者[n] .id,

患者[n] .forename,& patient [n] .initial,patient [n]。姓氏,

& patient [n] .day_of_entry,& patient [n] .max_wait)!= EOF){

n ++;

}

fclose(fptr);

//循环继续程序

while(loop!= 0){

//保持程序运行

//显示菜单

printf(" \ n\ n");

printf("%) d \ n",day_now());

printf(" _________________________________________ \ n");

printf(" | ------- ---- NHS队列控制----------- | \ n");

printf(" |创建新患者\t-按1 \ t | \ n");

printf(" |删除患者\t-按2 \t | \ n");

printf(" |找到病人\ t \ t-按3 \ t | \ n);

printf(" | List Queue \t\t- Press 4 \t | \ n");

printf(" |治疗下一位患者\t-按5 \ t | \ n");

printf(" | Quit \t\t\t-按6 \t | \ n");

printf(" | _______________________________________ | \ n");

printf(" Choice:");

scanf("%d",& Choice) );

printf(" \ n");

//做出选择,执行功能

开关(选择){

//新病人

案例1:

limit = n;

if(limit< 21){

list_queue();

printf(" \ n请输入以下详细信息\ n");

printf("什么队列号你想把这个病人

给?\ n");

scanf("%d"& Qnum);

printf(患者ID:);

scanf("%d",& patient [20] .id);

printf (" Forename:");

scanf("%s",patient [20] .forename);

printf(" Middle Initial:" );

scanf("%c",& patient [20] .initial);

printf(" Surname:");

scanf(" %s",patient [20]。姓氏);

printf(最长等待时间:);

scanf("%d", & patient [20] .max_wait);

患者[20] .day_of_entry = day_now();

error = insert_patient(Qnum,patient [20]);

if(error == -1){

printf(错误 - 患者存在!\ n);

}

else {

printf(" \ nPatient Inserted!\ n");

}

}

else {

printf(" Array is Full!\ n");

}

break;

}

返回0;

}


//这是添加功能

int insert_patient(int index,struct details newpatient){

int i = 0;

int n = 0;

int y = find_patient_id(index);

int x;

int error;


FILE * FPTR; //将文件指针声明为fptr

fptr = fopen(" queue.dat"," r");

while(fscanf(fptr,") ;%d%s%c%s%d%d [^ \ n]",& patient [n] .id,

patient [n] .forename,& patient [ n] .initial,patient [n]。姓,

& patient [n] .day_of_entry,& patient [n] .max_wait)!= EOF){

n ++;

}

fclose(fptr);


if(y == -1){

fptr = fopen(" queue.dat"," w");

for(i = 0; i< = index-2; i ++){

fprintf(fptr,"%d",patient [i] .id);

fprintf(fptr,"%s",patient [i] .forename);

fprintf(fptr,"%c",patient [i] .initial);

fprintf(fptr,"%s",patient [i]。姓氏)​​;

fprintf(fptr,"%d",patient [i] .day_of_entry);

fprintf(fptr,"%d \ n" ,耐心[i] .max_wait);

}


fprintf(fptr,"%d",patient [20] .id);

fprintf(fptr,"%s",patient [20] .forename);

fprintf(fptr,"%c",patient [20] .initial);

fprintf(fptr,"%s",patient [20] .surname);

fprintf(fptr,"%d",patient [20] .day_of_entry);

fprintf(fptr,"%d \ n",patient [20] .max_wait);


for(x = index; x< = n + 1; x ++){

fprintf(fptr,"%d",patient [x] .id);

fprintf(fptr,"%s ",patient [x] .forename);

fprintf(fptr,"%c",patient [x] .initial);

fprintf(fptr, %s,患者[x]。姓氏);

fprintf(fptr,%d,患者[x] .day_of_entry);

fprintf(fptr,"%d \ n",patient [x] .max_wait);

}

error = 0;

}

else if(y!= 0){

error = -1;

}

fclose( fptr);

返回错误;

}

解决方案

28 2007年5月12:14:33 - 0700,ch **** @ gmail.com < ch **** @ gmail.com>

写道:


> Ok这是一个问题,我有一个假想我需要的数据库程序代码,添加一个我有函数inser_patient的病人。但是当我试图输入细节时,它并不像我想要的那样完成。



我们应该猜猜你在说什么吗?你想要什么?b $ b想要什么?究竟发生了什么?


>
代码:

#include< stdio.h>
#include < stdlib.h>
#include< time.h>
#include< string.h>

#define MAXPATIENTS 20

struct details {
int id;
char forename [20];
char initial;
char surname [20];
int day_of_entry;
int max_wait ;
};

struct details患者[MAXPATIENTS];
int npatients = 0;

int insert_patient(int index,struct details newpatient);

int main(void){
int Choice;
int id;
int loop = 1;
int n = 0;
int error = 0;
int limit;
int Qnum;

FILE * fptr; //将文件指针声明为fptr
fptr = fopen(" queue.dat"," r"); //打开queue.dat到fptr



你应该验证fopen是否成功。


> //读取
while(fscanf(fptr,"%d%s%c%s%d%d [^ \ n]",& patient [n] .id,
患者[n] .forename,& patient [n] .initial,patient [n]。姓氏,
&patient [n] .day_of_entry,& patient [n] .max_wait)!= EOF){



这是错误的测试。 fscanf仅在没有数据转换时才返回EOF。只有当返回值为6时才应该继续。


>的n ++;



你永远不会检查你的

数组中元素数量是否溢出。


> }
fclose(fptr);
//循环继续程序
while(循环!= 0){
//保持程序运行
//显示菜单
printf(" \ n \ nn");
printf("%d \ n",day_now());
printf(" _________________________________________ \ n" ;);
printf(" | ----------- NHS队列控制----------- | \ n");
printf( |创建新患者\t-按1 \t | \ n);
printf(" |删除患者\t-按2 \t | \ n");
printf(" | Find Patient \t\t-按3 \t | \ n");
printf(" | List Queue \t\t- Press 4 \\ \\ t | \\ t | \\ t | \\ n \\ n; \\ n>打印ff(&|)|" | |处理下一位患者\t-按5 \t | \ n");
printf(" | Quit \ t \t\t-按6 \t | \ n");
printf(" | _______________________________________ | \ n");
printf(" Choice:");
s canf("%d"& Choice);
printf(" \ n");
//做出选择,执行功能
开关(选择){
新病人
案例1:
limit = n;
if(limit< 21){



你永远不会使用限制,所以你为什么要关心它的价值是什么。


> list_queue();



此功能的范围没有原型。


> printf(" \ n请输入以下详细信息\ n");
printf(你希望将这名病人放在什么队列号码?
?;
scanf("%d"& Qnum);
printf(" Patient ID:");



在缓冲系统上,调用不以''\ n'结尾的printf可能不会出现
在系统等待输入之前。如果您希望输入

与提示符出现在同一行,您应该添加

fflush(stdout);

以确保缓冲区被刷新到流中。


> scanf("%d",& patient [20] .id);



每次使用患者[20]都会调用未定义的行为。有效的

下标是0到19(MAXPATIENTS-1)。


> printf(" Forename:");
scanf("%s",patient [20] .forename);
printf(" Middle Initial:");
scanf (%c,& patient [20] .initial);



这将导致以后对scanf的任何调用出现问题。要输入初始的
,你必须按两个键,一个用于写字母,

一个用于输入。这将导致输入

流中的两个字符,一个用于字母,另一个用于输入'\\ n'。 %c只会消耗这封信。
消费这封信。 ''\ n''将保留在流中并提前终止

下一个scanf。


> printf(" Surname:");
scanf("%s",patient [20] .surname);
printf(" Maximum Waiting Time:");
scanf("%d",& patient [20] .max_wait);
患者[20] .day_of_entry = day_now();
错误= insert_patient(Qnum,患者[20]) ;



虽然传递结构是完全合法的,但通常的建议是,如果结构为<,则传递指向结构的指针。 br />
大一点琐碎。


> if(error == -1){
printf(Error - Patient exists!\ n);
}
else {
printf(" \ nPatient)已插入!\ n;;
}
}
其他{
printf(数组已满!\ n);
} 休息;

}

返回0;
}
//这是添加函数
int insert_patient( int index,struct details newpatient){
int i = 0;
int n = 0;
int y = find_patient_id(index);



此函数的范围没有原型。你也忘了

提供这个函数的定义。


> int x;
int error;

FILE * fptr; //将文件指针声明为fptr



你真的认为这个评论包含任何有用的信息吗?


> fptr = fopen(" queue.dat"," r");
while(fscanf(fptr,"%d%s%c%s%d%d [^ \ n]", & patient [n] .id,
患者[n] .forename,& patient [n] .initial,patient [n]。姓氏,
&患者[n] .day_of_entry,& ; patient [n] .max_wait)!= EOF){



您已经将记录读回到患者身上。为什么你再次阅读它们?$ b $ class =post_quotes>
> n ++;
}
fclose(fptr);

if(y == -1){
fptr = fopen(" queue.dat"," w();
for(i = 0; i< = index-2; i ++){
fprintf(fptr,"%d",patient [i] .id);
fprintf(fptr,"%s",patient [i] .forename);
fprintf(fptr,"%c",patient [i] .initial);



你写的记录的字段没有插入字符

。你对fscanf的调用如何知道

forename结束和初始开始的时间?


> fprintf(fptr,"%s",patient [i]。姓);
fprintf(fptr,"%d",patient [i] .day_of_entry);
fprintf(fptr, %d \ n,患者[i] .max_wait);



同义词和两个整数字段之间或day_of_entry

和max_wait之间的数字。


> fprintf(fptr,"%d",patient [20] .id);



患者[20]仍然不存在。


> fprintf(fptr,"%s",patient [20] .forename);
fprintf(fptr,"%c",patient [20] .initial);
fprintf(fptr, %s,患者[20]。姓氏);
fprintf(fptr,%d,患者[20] .day_of_entry);
fprintf(fptr,"%d \ n,耐心[20] .max_wait);

for(x = index; x< = n + 1; x ++){



为什么n + 1?这可以确保您处理无关的数据。幸运的是

(或un-),数据被初始化,因为患者处于文件范围。


你的意思是n-1?这是有道理的,但常见的习语是

i< n,不是我< = n-1。


> fprintf(fptr,"%d",patient [x] .id);
fprintf(fptr,"%s",patient [x] .forename);
fprintf(fptr, %c,患者[x]。初始);
fprintf(fptr,%s,患者[x]。姓氏);
fprintf(fptr,"%d ",patient [x] .day_of_entry);
fprintf(fptr,"%d \ n",patient [x] .max_wait);
}
错误= 0;
}
如果(y!= 0){
错误= -1;
}
fclose(fptr);
返回错误;
}



删除del电子邮件


5月28日,21:23,Barry Schwarz< schwa ... @ doezl.netwrote:


2007年5月28日12:14:33 -0700,chu ... @ gmail.com < chu ... @ gmail.com>

写道:


Ok这是一个问题,我有一个假想的数据库程序,我需要

来编码,添加一个我有函数inser_patient的病人。但是当我想要输入细节时,它并没有按照我想要的方式工作。



我们应该猜猜你在说什么吗?你想要什么?b $ b想要什么?究竟发生了什么?



代码:


#include< stdio.h>

#include< stdlib.h>

#include< time.h>

#include < string.h中>


#define MAXPATIENTS 20


struct details {

int id;

char forename [20];

char initial;

char surname [20];

int day_of_entry;

int max_wait;

};


struct details患者[MAXPATIENTS];

int npatients = 0;


int insert_patient(int index,struct details newpatient);


int main(void){

int Choice;

int id;

int loop = 1;

int n = 0;

int error = 0;

int limit;

int Qnum;


FILE * fptr; //将文件指针声明为fptr

fptr = fopen(" queue.dat"," r"); //打开queue.dat到fptr



你应该验证fopen是否成功。


//阅读

while(fscanf(fptr,"%d%s%c%s%d%d [^ \ n]",& patient [n] .id,

patient [n] .forename,& patient [n] .initial,patient [n]。姓氏,

& patient [n] .day_of_entry,& patient [n] .max_wait)!= EOF){



这是错误的测试。 fscanf仅在没有数据转换时才返回EOF。只有当返回值为6时才应该继续。


n ++;



你永远不会检查你的

数组中元素数量是否溢出。


}

fclose(fptr);

//循环继续程序

while(loop!= 0){

//保持程序运行

//显示菜单

printf(" \ n\ n");

printf("%d \ n",day_now());

printf(" _________________________________________ \ n");

printf(" ; | ----------- NHS队列控制----------- | \ n");

printf(" |创建新患者) \t-按1 \t | \ n");

printf(" |删除患者\t-按2 \t | \ n");

printf(" | Find Patient \t\t- Press 3 \t | \ n");

printf( " | List Queue \t\t-按4 \t | \ n");

printf(" |治疗下一位患者\t-按5 \ t | \ n");

printf(" | Quit \t\t\t-按6 \t | \ n");

printf(" | _______________________________________ | \ n");

printf(" Choice:");

scanf("%d",& Choice) );

printf(" \ n");

//做出选择,执行功能

开关(选择){

//新病人

案例1:

limit = n;

if(limit< 21){



你永远不会使用限制,所以你为什么要关心它的价值是什么。


list_queue ();



这个函数的范围没有原型。


printf(" \\\
Please enter以下详细信息\ n");

printf(你希望将这个病人放在什么队列号码上?/ b $ b到?\ n);

scanf("%d"& Qnum);

printf(" Patient ID:");



在缓冲系统上,调用不以''\ n'结尾的printf可能不会出现
在系统等待输入之前。如果您希望输入

与提示符出现在同一行,您应该添加

fflush(stdout);

以确保缓冲区被刷新到流中。


scanf("%d",& patient [20] .id);



每次使用患者[20]都会调用未定义的行为。有效的

下标为0到19(MAXPATIENTS-1)。


printf(" Forename:");

scanf("%s",patient [20] .forename);

printf(" Middle Initial:");

scanf( %c,& patient [20] .initial);



这将导致以后对scanf的任何调用出现问题。要输入初始的
,你必须按两个键,一个用于写字母,

一个用于输入。这将导致输入

流中的两个字符,一个用于字母,另一个用于输入'\\ n'。 %c只会消耗这封信。
消费这封信。 ''\ n''将保留在流中并提前终止

下一个scanf。


printf(" Surname: ");

scanf("%s",patient [20] .surname);

printf(" Maximum Waiting Time:");

scanf("%d",& patient [20] .max_wait);

病人[20] .day_of_entry = day_now();

error = insert_patient(Qnum,patient [20]);



虽然传递结构是完全合法的,但通常的建议是,如果结构为<,则传递一个指向结构的指针br />
大一点琐碎。


if(error == -1){

printf(" Error - 病人存在!\ n;

}

else {

printf(" \ nPatient Inserted!\ n") ;

}

}

else {

printf(" Array is Full!\ n") ;

}

休息;

}

返回0;

}


//这是添加函数

int insert_patient(int index,struct details newpatient){

int i = 0;

int n = 0;

int y = find_patient_id(index);



此功能的范围没有原型。你也忘了

提供这个函数的定义。


int x;

int error;


FILE * fptr; //将文件指针声明为fptr



你真的认为这个评论包含任何有用的信息吗?


fptr = fopen(" queue) .dat"," r");

while(fscanf(fptr,"%d%s%c%s%d%d [^ \ n]",& patient [n] .id,

病人[n] .forename,& patient [n] .initial,patient [n]。姓氏,

& patient [n ] .day_of_entry,& patient [n] .max_wait)!= EOF){



您已经将记录读回到患者身上。你为什么再次阅读它们?$ block $ class =post_quotes>
n ++;

}

FCLOSE(FPTR);


if(y == -1){

fptr = fopen(" queue.dat"," w");

for(i = 0; i< = index-2; i ++){

fprintf(fptr,"%d",patient [i ] .id);

fprintf(fptr,"%s",patient [i] .forename);

fprintf(fptr,"%c" ,患者[I] .initial);



你写的记录的字段没有插入字符

。你对fscanf的调用如何知道

forename结束和初始开始?


fprintf(fptr,"%s" ,耐心[i]。姓氏);

fprintf(fptr,"%d",patient [i] .day_of_entry);

fprintf(fptr," %d \ n",patient [i] .max_wait);



同名和两个整数字段之间或day_of_entry

和max_wait之间同上。


}


fprintf(fptr,"%d",patient [20] .id);



患者[20]仍然不存在。


fprintf(fptr,"%s" ;,患者[20] .forename);

fprintf(fptr,"%c",patient [20] .initial);

fprintf(fptr," ;%s",patient [20]。姓氏);

fprintf(fptr,"%d",patient [20] .day_of_entry);

fprintf (fptr,%d \ n,患者[20] .max_wait);


for(x = index; x< = n + 1; x ++){



为什么n + 1?这可以确保您处理无关的数据。幸运的是

(或un-),数据被初始化,因为患者处于文件范围。


你的意思是n-1?这是有道理的,但常见的习语是

i< n,不是我< = n-1。


fprintf(fptr,"%d",patient [x] .id);

fprintf(fptr,"%s",patient [x] .forename);

fprintf(fptr,"%c",patient [x] .initial);

fprintf(fptr,"%s",patient [x] .surname);

fprintf(fptr,"%d",patient [x] .day_of_entry);

fprintf(fptr,"%d \ n",patient [x] .max_wait);

}

错误= 0;

}

否则if(y!= 0){

error = -1;

}

fclose(fptr);

返回错误;

}



删除电子邮件的del



当我尝试在患者中输入

max_wait时,如何避免程序跳过[ 20] .max_wait

谢谢

Chris


5月28日21:23,Barry Schwarz< schwa ... @ doezl.netwrote:


2007年5月28日12:14:33 -0700,chu ... @ gmail.com < chu ... @ gmail.com>

写道:


Ok这是一个问题,我有一个假想的数据库程序,我需要

来编码,添加一个我有函数inser_patient的病人。但是当我想要输入细节时,它并没有按照我想要的方式工作。



我们应该猜猜你在说什么吗?你想要什么?b $ b想要什么?究竟发生了什么?



代码:


#include< stdio.h>

#include< stdlib.h>

#include< time.h>

#include < string.h中>


#define MAXPATIENTS 20


struct details {

int id;

char forename [20];

char initial;

char surname [20];

int day_of_entry;

int max_wait;

};


struct details患者[MAXPATIENTS];

int npatients = 0;


int insert_patient(int index,struct details newpatient);


int main(void){

int Choice;

int id;

int loop = 1;

int n = 0;

int error = 0;

int limit;

int Qnum;


FILE * fptr; //将文件指针声明为fptr

fptr = fopen(" queue.dat"," r"); //Opens queue.dat to fptr



You should verify that fopen succeeded.

\t
\t\t\t\t //Reading

while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,

patient[n].forename, &patient[n].initial, patient[n].surname,

&patient[n].day_of_entry, &patient[n].max_wait) != EOF){



This is the wrong test. fscanf returns EOF only if no data was

converted. You should be proceeding only if the return value is 6.

\t
\t\t\t\t n++;



You never check for n overflowing the number of elements in your

array.

\t
\t\t\t\t }

fclose(fptr);

//Loop that continues the program

while(loop != 0){

//To keep program running

//Displaying Menu

printf("\n\n");

printf("%d \n",day_now());

printf("_________________________________________\ n");

printf("|-----------NHS Queue Control-----------|\n");

printf("| Create New Patient \t- Press 1\t|\n");

printf("| Delete Patient \t- Press 2\t|\n");

printf("| Find Patient \t\t- Press 3\t|\n");

printf( "| List Queue \t\t- Press 4\t|\n");

printf("| Treate Next Patient \t- Press 5\t| \n");

printf("| Quit \t\t\t- Press 6\t|\n");

printf("|_______________________________________|\ n");

printf("Choice: ");

scanf("%d",&Choice);

printf("\n");

//Choice made, carrying out function

switch (Choice){

//New Patient

case 1:

limit = n;

if(limit < 21){



You never use limit so why do you care what it’’s value is.

\t
\t\t\t\t list_queue();



There is no prototype in scope for this function.

\t
\t\t\t\t printf("\nPlease enter the following details\n");

printf("What Queue Number would you like to place this patient

to?\n");

scanf("%d", &Qnum);

printf("Patient ID: ");



On a buffered system, calls to printf that don’’t end with a ’’\n’’ may

not appear before the system waits for input. If you want the input

to appear on the same line as the prompt, you should add

fflush(stdout);

to insure the buffer is flushed to the stream.

\t
\t\t\t\t scanf("%d", &patient[20].id);



Every use of patient[20] invokes undefined behavior. The valid

subscripts are 0 through 19 (MAXPATIENTS-1).

\t
\t\t\t\t printf("Forename: ");

scanf("%s", patient[20].forename);

printf("Middle Initial: ");

scanf("%c ", &patient[20].initial);



This will cause problems with any following calls to scanf. To enter

the initial, you will have to press two keys, one for the letter and

one for ENTER. This will result in two characters in the input

stream, one for the letter and a ’’\n’’ for the ENTER. The %c will only

consume the letter. The ’’\n’’ will stay in the stream and terminate

the next scanf prematurely.

\t
\t\t\t\t printf("Surname: ");

scanf("%s ", patient[20].surname);

printf("Maximum Waiting Time: ");

scanf("%d ", &patient[20].max_wait);

patient[20].day_of_entry = day_now();

error = insert_patient(Qnum, patient[20]);



While it is perfectly legal to pass a struct, the common

recommendation is to pass a pointer to the struct if the structure is

larger that trivial.

\t
\t\t\t\t if(error == -1){

printf("Error - Patient exists!\n");

}

else {

printf("\nPatient Inserted!\n");

}

}

else {

printf("Array is Full!\n");

}

break;

}

return 0;

}

\t
\t\t\t\t//This is the add function

int insert_patient(int index, struct details newpatient) {

int i = 0;

int n = 0;

int y = find_patient_id(index) ;



There is no prototype in scope for this function. You also forgot to

provide the definition of this function.

\t
\t\t\t\t int x;

int error;

\t
\t\t\t\t FILE * fptr; //Declares file pointer as "fptr"



Do you really think this comment contains any useful information?

\t
\t\t\t\t fptr = fopen("queue.dat", "r");

while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,

patient[n].forename, &patient[n].initial, patient[n].surname,

&patient[n].day_of_entry, &patient[n].max_wait) != EOF){



You already read the records into patient back in main. Why are you

reading them again?

\t
\t\t\t\t n++;

}

fclose(fptr);

\t
\t\t\t\t if(y == -1){

fptr = fopen("queue.dat", "w");

for(i=0;i<=index-2;i++){

fprintf(fptr,"%d ",patient[i].id);

fprintf(fptr,"%s ",patient[i].forename);

fprintf(fptr,"%c ",patient[i].initial);



You write the fields of the record with no intervening characters

between them. How is your call to fscanf supposed to know where

forename ends and initial begins?

\t
\t\t\t\t fprintf(fptr,"%s ",patient[i].surname);

fprintf(fptr,"%d ",patient[i].day_of_entry);

fprintf(fptr,"%d \n",patient[i].max_wait);



Ditto between surname and both integer fields or between day_of_entry

and max_wait.

\t
\t\t\t\t }

\t
\t\t\t\t fprintf(fptr,"%d ",patient[20].id);



patient[20] still does not exist.

\t
\t\t\t\t fprintf(fptr,"%s ",patient[20].forename);

fprintf(fptr,"%c ",patient[20].initial);

fprintf(fptr,"%s ",patient[20].surname);

fprintf(fptr,"%d ",patient[20].day_of_entry);

fprintf(fptr,"%d \n",patient[20].max_wait);

\t
\t\t\t\t for(x=index;x<=n+1;x++){



Why n+1? This insures you will process extraneous data. Fortunately

(or un-), the data is initialized since patient is at file scope.


Did you mean n-1? That would make sense but the common idiom is

i < n, not i <= n-1.

\t
\t\t\t\t fprintf(fptr,"%d ",patient[x].id);

fprintf(fptr,"%s ",patient[x].forename);

fprintf(fptr,"%c ",patient[x].initial);

fprintf(fptr,"%s ",patient[x].surname);

fprintf(fptr,"%d ",patient[x].day_of_entry);

fprintf(fptr,"%d \n",patient[x].max_wait);

}

error = 0;

}

else if (y != 0){

error = -1;

}

fclose(fptr);

return error;

}



Remove del for email



So how do I avoid the program from skipping when I try to type in the

max_wait, in patient[20].max_wait

Thanks

Chris


Ok Here is a problem, I got a imaginary database program that I need
to code, to add a patient I have function inser_patient. but when I
try to input the details it doesn''t quite work the way I wanted it to.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MAXPATIENTS 20

struct details {
int id;
char forename[20];
char initial;
char surname[20];
int day_of_entry;
int max_wait;
};

struct details patient[MAXPATIENTS];
int npatients = 0;

int insert_patient(int index, struct details newpatient);

int main (void) {
int Choice;
int id;
int loop = 1;
int n=0;
int error=0;
int limit;
int Qnum;

FILE * fptr; //Declares file pointer as "fptr"
fptr = fopen("queue.dat", "r"); //Opens queue.dat to fptr
//Reading
while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,
patient[n].forename, &patient[n].initial, patient[n].surname,
&patient[n].day_of_entry, &patient[n].max_wait) != EOF){
n++;
}
fclose(fptr);
//Loop that continues the program
while(loop != 0){
//To keep program running
//Displaying Menu
printf("\n\n");
printf("%d \n",day_now());
printf("_________________________________________\ n");
printf("|-----------NHS Queue Control-----------|\n");
printf("| Create New Patient \t- Press 1\t|\n");
printf("| Delete Patient \t- Press 2\t|\n");
printf("| Find Patient \t\t- Press 3\t|\n");
printf("| List Queue \t\t- Press 4\t|\n");
printf("| Treate Next Patient \t- Press 5\t| \n");
printf("| Quit \t\t\t- Press 6\t|\n");
printf("|_______________________________________|\ n");
printf("Choice: ");
scanf("%d",&Choice);
printf("\n");
//Choice made, carrying out function
switch (Choice){
//New Patient
case 1:
limit = n;
if(limit < 21){
list_queue();
printf("\nPlease enter the following details\n");
printf("What Queue Number would you like to place this patient
to?\n");
scanf("%d", &Qnum);
printf("Patient ID: ");
scanf("%d", &patient[20].id);
printf("Forename: ");
scanf("%s", patient[20].forename);
printf("Middle Initial: ");
scanf("%c ", &patient[20].initial);
printf("Surname: ");
scanf("%s ", patient[20].surname);
printf("Maximum Waiting Time: ");
scanf("%d ", &patient[20].max_wait);
patient[20].day_of_entry = day_now();
error = insert_patient(Qnum, patient[20]);
if(error == -1){
printf("Error - Patient exists!\n");
}
else {
printf("\nPatient Inserted!\n");
}
}
else {
printf("Array is Full!\n");
}
break;
}
return 0;
}

//This is the add function
int insert_patient(int index, struct details newpatient) {
int i = 0;
int n = 0;
int y = find_patient_id(index) ;
int x;
int error;

FILE * fptr; //Declares file pointer as "fptr"
fptr = fopen("queue.dat", "r");
while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,
patient[n].forename, &patient[n].initial, patient[n].surname,
&patient[n].day_of_entry, &patient[n].max_wait) != EOF){
n++;
}
fclose(fptr);

if(y == -1){
fptr = fopen("queue.dat", "w");
for(i=0;i<=index-2;i++){
fprintf(fptr,"%d ",patient[i].id);
fprintf(fptr,"%s ",patient[i].forename);
fprintf(fptr,"%c ",patient[i].initial);
fprintf(fptr,"%s ",patient[i].surname);
fprintf(fptr,"%d ",patient[i].day_of_entry);
fprintf(fptr,"%d \n",patient[i].max_wait);
}

fprintf(fptr,"%d ",patient[20].id);
fprintf(fptr,"%s ",patient[20].forename);
fprintf(fptr,"%c ",patient[20].initial);
fprintf(fptr,"%s ",patient[20].surname);
fprintf(fptr,"%d ",patient[20].day_of_entry);
fprintf(fptr,"%d \n",patient[20].max_wait);

for(x=index;x<=n+1;x++){
fprintf(fptr,"%d ",patient[x].id);
fprintf(fptr,"%s ",patient[x].forename);
fprintf(fptr,"%c ",patient[x].initial);
fprintf(fptr,"%s ",patient[x].surname);
fprintf(fptr,"%d ",patient[x].day_of_entry);
fprintf(fptr,"%d \n",patient[x].max_wait);
}
error = 0;
}
else if (y != 0){
error = -1;
}
fclose(fptr);
return error;
}

解决方案

On 28 May 2007 12:14:33 -0700, "ch****@gmail.com" <ch****@gmail.com>
wrote:

>Ok Here is a problem, I got a imaginary database program that I need
to code, to add a patient I have function inser_patient. but when I
try to input the details it doesn''t quite work the way I wanted it to.

Are we supposed to guess what you are talking about? What did you
want? What actually happened?

>
Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MAXPATIENTS 20

struct details {
int id;
char forename[20];
char initial;
char surname[20];
int day_of_entry;
int max_wait;
};

struct details patient[MAXPATIENTS];
int npatients = 0;

int insert_patient(int index, struct details newpatient);

int main (void) {
int Choice;
int id;
int loop = 1;
int n=0;
int error=0;
int limit;
int Qnum;

FILE * fptr; //Declares file pointer as "fptr"
fptr = fopen("queue.dat", "r"); //Opens queue.dat to fptr

You should verify that fopen succeeded.

> //Reading
while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,
patient[n].forename, &patient[n].initial, patient[n].surname,
&patient[n].day_of_entry, &patient[n].max_wait) != EOF){

This is the wrong test. fscanf returns EOF only if no data was
converted. You should be proceeding only if the return value is 6.

> n++;

You never check for n overflowing the number of elements in your
array.

> }
fclose(fptr);
//Loop that continues the program
while(loop != 0){
//To keep program running
//Displaying Menu
printf("\n\n");
printf("%d \n",day_now());
printf("_________________________________________\ n");
printf("|-----------NHS Queue Control-----------|\n");
printf("| Create New Patient \t- Press 1\t|\n");
printf("| Delete Patient \t- Press 2\t|\n");
printf("| Find Patient \t\t- Press 3\t|\n");
printf("| List Queue \t\t- Press 4\t|\n");
printf("| Treate Next Patient \t- Press 5\t| \n");
printf("| Quit \t\t\t- Press 6\t|\n");
printf("|_______________________________________|\ n");
printf("Choice: ");
scanf("%d",&Choice);
printf("\n");
//Choice made, carrying out function
switch (Choice){
//New Patient
case 1:
limit = n;
if(limit < 21){

You never use limit so why do you care what it''s value is.

> list_queue();

There is no prototype in scope for this function.

> printf("\nPlease enter the following details\n");
printf("What Queue Number would you like to place this patient
to?\n");
scanf("%d", &Qnum);
printf("Patient ID: ");

On a buffered system, calls to printf that don''t end with a ''\n'' may
not appear before the system waits for input. If you want the input
to appear on the same line as the prompt, you should add
fflush(stdout);
to insure the buffer is flushed to the stream.

> scanf("%d", &patient[20].id);

Every use of patient[20] invokes undefined behavior. The valid
subscripts are 0 through 19 (MAXPATIENTS-1).

> printf("Forename: ");
scanf("%s", patient[20].forename);
printf("Middle Initial: ");
scanf("%c ", &patient[20].initial);

This will cause problems with any following calls to scanf. To enter
the initial, you will have to press two keys, one for the letter and
one for ENTER. This will result in two characters in the input
stream, one for the letter and a ''\n'' for the ENTER. The %c will only
consume the letter. The ''\n'' will stay in the stream and terminate
the next scanf prematurely.

> printf("Surname: ");
scanf("%s ", patient[20].surname);
printf("Maximum Waiting Time: ");
scanf("%d ", &patient[20].max_wait);
patient[20].day_of_entry = day_now();
error = insert_patient(Qnum, patient[20]);

While it is perfectly legal to pass a struct, the common
recommendation is to pass a pointer to the struct if the structure is
larger that trivial.

> if(error == -1){
printf("Error - Patient exists!\n");
}
else {
printf("\nPatient Inserted!\n");
}
}
else {
printf("Array is Full!\n");
}
break;
}
return 0;
}

//This is the add function
int insert_patient(int index, struct details newpatient) {
int i = 0;
int n = 0;
int y = find_patient_id(index) ;

There is no prototype in scope for this function. You also forgot to
provide the definition of this function.

> int x;
int error;

FILE * fptr; //Declares file pointer as "fptr"

Do you really think this comment contains any useful information?

> fptr = fopen("queue.dat", "r");
while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,
patient[n].forename, &patient[n].initial, patient[n].surname,
&patient[n].day_of_entry, &patient[n].max_wait) != EOF){

You already read the records into patient back in main. Why are you
reading them again?

> n++;
}
fclose(fptr);

if(y == -1){
fptr = fopen("queue.dat", "w");
for(i=0;i<=index-2;i++){
fprintf(fptr,"%d ",patient[i].id);
fprintf(fptr,"%s ",patient[i].forename);
fprintf(fptr,"%c ",patient[i].initial);

You write the fields of the record with no intervening characters
between them. How is your call to fscanf supposed to know where
forename ends and initial begins?

> fprintf(fptr,"%s ",patient[i].surname);
fprintf(fptr,"%d ",patient[i].day_of_entry);
fprintf(fptr,"%d \n",patient[i].max_wait);

Ditto between surname and both integer fields or between day_of_entry
and max_wait.

> }

fprintf(fptr,"%d ",patient[20].id);

patient[20] still does not exist.

> fprintf(fptr,"%s ",patient[20].forename);
fprintf(fptr,"%c ",patient[20].initial);
fprintf(fptr,"%s ",patient[20].surname);
fprintf(fptr,"%d ",patient[20].day_of_entry);
fprintf(fptr,"%d \n",patient[20].max_wait);

for(x=index;x<=n+1;x++){

Why n+1? This insures you will process extraneous data. Fortunately
(or un-), the data is initialized since patient is at file scope.

Did you mean n-1? That would make sense but the common idiom is
i < n, not i <= n-1.

> fprintf(fptr,"%d ",patient[x].id);
fprintf(fptr,"%s ",patient[x].forename);
fprintf(fptr,"%c ",patient[x].initial);
fprintf(fptr,"%s ",patient[x].surname);
fprintf(fptr,"%d ",patient[x].day_of_entry);
fprintf(fptr,"%d \n",patient[x].max_wait);
}
error = 0;
}
else if (y != 0){
error = -1;
}
fclose(fptr);
return error;
}


Remove del for email


On 28 May, 21:23, Barry Schwarz <schwa...@doezl.netwrote:

On 28 May 2007 12:14:33 -0700, "chu...@gmail.com" <chu...@gmail.com>
wrote:

Ok Here is a problem, I got a imaginary database program that I need
to code, to add a patient I have function inser_patient. but when I
try to input the details it doesn''t quite work the way I wanted it to.


Are we supposed to guess what you are talking about? What did you
want? What actually happened?


Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MAXPATIENTS 20

struct details {
int id;
char forename[20];
char initial;
char surname[20];
int day_of_entry;
int max_wait;
};

struct details patient[MAXPATIENTS];
int npatients = 0;

int insert_patient(int index, struct details newpatient);

int main (void) {
int Choice;
int id;
int loop = 1;
int n=0;
int error=0;
int limit;
int Qnum;

FILE * fptr; //Declares file pointer as "fptr"
fptr = fopen("queue.dat", "r"); //Opens queue.dat to fptr


You should verify that fopen succeeded.

//Reading
while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,
patient[n].forename, &patient[n].initial, patient[n].surname,
&patient[n].day_of_entry, &patient[n].max_wait) != EOF){


This is the wrong test. fscanf returns EOF only if no data was
converted. You should be proceeding only if the return value is 6.

n++;


You never check for n overflowing the number of elements in your
array.

}
fclose(fptr);
//Loop that continues the program
while(loop != 0){
//To keep program running
//Displaying Menu
printf("\n\n");
printf("%d \n",day_now());
printf("_________________________________________\ n");
printf("|-----------NHS Queue Control-----------|\n");
printf("| Create New Patient \t- Press 1\t|\n");
printf("| Delete Patient \t- Press 2\t|\n");
printf("| Find Patient \t\t- Press 3\t|\n");
printf("| List Queue \t\t- Press 4\t|\n");
printf("| Treate Next Patient \t- Press 5\t| \n");
printf("| Quit \t\t\t- Press 6\t|\n");
printf("|_______________________________________|\ n");
printf("Choice: ");
scanf("%d",&Choice);
printf("\n");
//Choice made, carrying out function
switch (Choice){
//New Patient
case 1:
limit = n;
if(limit < 21){


You never use limit so why do you care what it''s value is.

list_queue();


There is no prototype in scope for this function.

printf("\nPlease enter the following details\n");
printf("What Queue Number would you like to place this patient
to?\n");
scanf("%d", &Qnum);
printf("Patient ID: ");


On a buffered system, calls to printf that don''t end with a ''\n'' may
not appear before the system waits for input. If you want the input
to appear on the same line as the prompt, you should add
fflush(stdout);
to insure the buffer is flushed to the stream.

scanf("%d", &patient[20].id);


Every use of patient[20] invokes undefined behavior. The valid
subscripts are 0 through 19 (MAXPATIENTS-1).

printf("Forename: ");
scanf("%s", patient[20].forename);
printf("Middle Initial: ");
scanf("%c ", &patient[20].initial);


This will cause problems with any following calls to scanf. To enter
the initial, you will have to press two keys, one for the letter and
one for ENTER. This will result in two characters in the input
stream, one for the letter and a ''\n'' for the ENTER. The %c will only
consume the letter. The ''\n'' will stay in the stream and terminate
the next scanf prematurely.

printf("Surname: ");
scanf("%s ", patient[20].surname);
printf("Maximum Waiting Time: ");
scanf("%d ", &patient[20].max_wait);
patient[20].day_of_entry = day_now();
error = insert_patient(Qnum, patient[20]);


While it is perfectly legal to pass a struct, the common
recommendation is to pass a pointer to the struct if the structure is
larger that trivial.

if(error == -1){
printf("Error - Patient exists!\n");
}
else {
printf("\nPatient Inserted!\n");
}
}
else {
printf("Array is Full!\n");
}
break;
}
return 0;
}

//This is the add function
int insert_patient(int index, struct details newpatient) {
int i = 0;
int n = 0;
int y = find_patient_id(index) ;


There is no prototype in scope for this function. You also forgot to
provide the definition of this function.

int x;
int error;

FILE * fptr; //Declares file pointer as "fptr"


Do you really think this comment contains any useful information?

fptr = fopen("queue.dat", "r");
while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,
patient[n].forename, &patient[n].initial, patient[n].surname,
&patient[n].day_of_entry, &patient[n].max_wait) != EOF){


You already read the records into patient back in main. Why are you
reading them again?

n++;
}
fclose(fptr);

if(y == -1){
fptr = fopen("queue.dat", "w");
for(i=0;i<=index-2;i++){
fprintf(fptr,"%d ",patient[i].id);
fprintf(fptr,"%s ",patient[i].forename);
fprintf(fptr,"%c ",patient[i].initial);


You write the fields of the record with no intervening characters
between them. How is your call to fscanf supposed to know where
forename ends and initial begins?

fprintf(fptr,"%s ",patient[i].surname);
fprintf(fptr,"%d ",patient[i].day_of_entry);
fprintf(fptr,"%d \n",patient[i].max_wait);


Ditto between surname and both integer fields or between day_of_entry
and max_wait.

}

fprintf(fptr,"%d ",patient[20].id);


patient[20] still does not exist.

fprintf(fptr,"%s ",patient[20].forename);
fprintf(fptr,"%c ",patient[20].initial);
fprintf(fptr,"%s ",patient[20].surname);
fprintf(fptr,"%d ",patient[20].day_of_entry);
fprintf(fptr,"%d \n",patient[20].max_wait);

for(x=index;x<=n+1;x++){


Why n+1? This insures you will process extraneous data. Fortunately
(or un-), the data is initialized since patient is at file scope.

Did you mean n-1? That would make sense but the common idiom is
i < n, not i <= n-1.

fprintf(fptr,"%d ",patient[x].id);
fprintf(fptr,"%s ",patient[x].forename);
fprintf(fptr,"%c ",patient[x].initial);
fprintf(fptr,"%s ",patient[x].surname);
fprintf(fptr,"%d ",patient[x].day_of_entry);
fprintf(fptr,"%d \n",patient[x].max_wait);
}
error = 0;
}
else if (y != 0){
error = -1;
}
fclose(fptr);
return error;
}


Remove del for email


So how do I avoid the program from skipping when I try to type in the
max_wait, in patient[20].max_wait
Thanks
Chris


On 28 May, 21:23, Barry Schwarz <schwa...@doezl.netwrote:

On 28 May 2007 12:14:33 -0700, "chu...@gmail.com" <chu...@gmail.com>
wrote:

Ok Here is a problem, I got a imaginary database program that I need
to code, to add a patient I have function inser_patient. but when I
try to input the details it doesn''t quite work the way I wanted it to.


Are we supposed to guess what you are talking about? What did you
want? What actually happened?


Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

#define MAXPATIENTS 20

struct details {
int id;
char forename[20];
char initial;
char surname[20];
int day_of_entry;
int max_wait;
};

struct details patient[MAXPATIENTS];
int npatients = 0;

int insert_patient(int index, struct details newpatient);

int main (void) {
int Choice;
int id;
int loop = 1;
int n=0;
int error=0;
int limit;
int Qnum;

FILE * fptr; //Declares file pointer as "fptr"
fptr = fopen("queue.dat", "r"); //Opens queue.dat to fptr


You should verify that fopen succeeded.

//Reading
while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,
patient[n].forename, &patient[n].initial, patient[n].surname,
&patient[n].day_of_entry, &patient[n].max_wait) != EOF){


This is the wrong test. fscanf returns EOF only if no data was
converted. You should be proceeding only if the return value is 6.

n++;


You never check for n overflowing the number of elements in your
array.

}
fclose(fptr);
//Loop that continues the program
while(loop != 0){
//To keep program running
//Displaying Menu
printf("\n\n");
printf("%d \n",day_now());
printf("_________________________________________\ n");
printf("|-----------NHS Queue Control-----------|\n");
printf("| Create New Patient \t- Press 1\t|\n");
printf("| Delete Patient \t- Press 2\t|\n");
printf("| Find Patient \t\t- Press 3\t|\n");
printf("| List Queue \t\t- Press 4\t|\n");
printf("| Treate Next Patient \t- Press 5\t| \n");
printf("| Quit \t\t\t- Press 6\t|\n");
printf("|_______________________________________|\ n");
printf("Choice: ");
scanf("%d",&Choice);
printf("\n");
//Choice made, carrying out function
switch (Choice){
//New Patient
case 1:
limit = n;
if(limit < 21){


You never use limit so why do you care what it''s value is.

list_queue();


There is no prototype in scope for this function.

printf("\nPlease enter the following details\n");
printf("What Queue Number would you like to place this patient
to?\n");
scanf("%d", &Qnum);
printf("Patient ID: ");


On a buffered system, calls to printf that don''t end with a ''\n'' may
not appear before the system waits for input. If you want the input
to appear on the same line as the prompt, you should add
fflush(stdout);
to insure the buffer is flushed to the stream.

scanf("%d", &patient[20].id);


Every use of patient[20] invokes undefined behavior. The valid
subscripts are 0 through 19 (MAXPATIENTS-1).

printf("Forename: ");
scanf("%s", patient[20].forename);
printf("Middle Initial: ");
scanf("%c ", &patient[20].initial);


This will cause problems with any following calls to scanf. To enter
the initial, you will have to press two keys, one for the letter and
one for ENTER. This will result in two characters in the input
stream, one for the letter and a ''\n'' for the ENTER. The %c will only
consume the letter. The ''\n'' will stay in the stream and terminate
the next scanf prematurely.

printf("Surname: ");
scanf("%s ", patient[20].surname);
printf("Maximum Waiting Time: ");
scanf("%d ", &patient[20].max_wait);
patient[20].day_of_entry = day_now();
error = insert_patient(Qnum, patient[20]);


While it is perfectly legal to pass a struct, the common
recommendation is to pass a pointer to the struct if the structure is
larger that trivial.

if(error == -1){
printf("Error - Patient exists!\n");
}
else {
printf("\nPatient Inserted!\n");
}
}
else {
printf("Array is Full!\n");
}
break;
}
return 0;
}

//This is the add function
int insert_patient(int index, struct details newpatient) {
int i = 0;
int n = 0;
int y = find_patient_id(index) ;


There is no prototype in scope for this function. You also forgot to
provide the definition of this function.

int x;
int error;

FILE * fptr; //Declares file pointer as "fptr"


Do you really think this comment contains any useful information?

fptr = fopen("queue.dat", "r");
while (fscanf(fptr,"%d %s %c %s %d %d[^\n]", &patient[n].id,
patient[n].forename, &patient[n].initial, patient[n].surname,
&patient[n].day_of_entry, &patient[n].max_wait) != EOF){


You already read the records into patient back in main. Why are you
reading them again?

n++;
}
fclose(fptr);

if(y == -1){
fptr = fopen("queue.dat", "w");
for(i=0;i<=index-2;i++){
fprintf(fptr,"%d ",patient[i].id);
fprintf(fptr,"%s ",patient[i].forename);
fprintf(fptr,"%c ",patient[i].initial);


You write the fields of the record with no intervening characters
between them. How is your call to fscanf supposed to know where
forename ends and initial begins?

fprintf(fptr,"%s ",patient[i].surname);
fprintf(fptr,"%d ",patient[i].day_of_entry);
fprintf(fptr,"%d \n",patient[i].max_wait);


Ditto between surname and both integer fields or between day_of_entry
and max_wait.

}

fprintf(fptr,"%d ",patient[20].id);


patient[20] still does not exist.

fprintf(fptr,"%s ",patient[20].forename);
fprintf(fptr,"%c ",patient[20].initial);
fprintf(fptr,"%s ",patient[20].surname);
fprintf(fptr,"%d ",patient[20].day_of_entry);
fprintf(fptr,"%d \n",patient[20].max_wait);

for(x=index;x<=n+1;x++){


Why n+1? This insures you will process extraneous data. Fortunately
(or un-), the data is initialized since patient is at file scope.

Did you mean n-1? That would make sense but the common idiom is
i < n, not i <= n-1.

fprintf(fptr,"%d ",patient[x].id);
fprintf(fptr,"%s ",patient[x].forename);
fprintf(fptr,"%c ",patient[x].initial);
fprintf(fptr,"%s ",patient[x].surname);
fprintf(fptr,"%d ",patient[x].day_of_entry);
fprintf(fptr,"%d \n",patient[x].max_wait);
}
error = 0;
}
else if (y != 0){
error = -1;
}
fclose(fptr);
return error;
}


Remove del for email


So how do I avoid the program from skipping when I try to type in the
max_wait, in patient[20].max_wait
Thanks
Chris


这篇关于怎么了?我不能添加......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆