Home > Back-end >  Why the file cannot be opened?
Why the file cannot be opened?

Time:11-25

#include
#include
#include
#include

Typedef struct {
Int arrive;//arrival time
Int treat;//service time
} QNODE;

Typedef struct node {
QNODE data;
Struct node * next;//the elements in the queue information
} LNODE * QueuePtr;

Typedef struct {/queue/chain type
QueuePtr front;//team head pointer
QueuePtr rear;//of the pointer
} LinkQueue;

Void the EnQueue (LinkQueue * link, QNODE x)//into the queue
{
LNODE * p=(LNODE *) malloc (sizeof (LNODE));
If (p==NULL) exit (0);
P - & gt; data=https://bbs.csdn.net/topics/x;
P - & gt; Next=NULL;
If (the link - & gt; The front==NULL)
{
The link - & gt; The front=p;
The link - & gt; Rear=link - & gt; The front;
}
The else
{
(link - & gt; Rear) - & gt; Next=p;
The link - & gt; Rear=p;
}
Free (p);
}

Void to DeQueue (LinkQueue * link, QNODE * x)//the queue
{
LNODE * p=link - & gt; The front;
If (the link - & gt; The front==NULL)
exit(0);
The link - & gt; The front=p - & gt; Next;
* x=p - & gt; The data;
If (the link - & gt; The front==NULL)
The link - & gt; Rear=NULL;
Free (p);
}




Int main ()
{
Char Fname [100].
The FILE * fp.
Int have=0, dwaite=0, cwaite=0, the count=0, clock=0, finish=0;
QNODE curr, temp;
LinkQueue link;
The link. The front=NULL;
The link. The rear=NULL;

Printf (" input file name: ");
The scanf (" % s ", Fname);/* input of customer simulation data file filename */
If ((fp=fopen (" Fname ", "r"))==NULL) {/* open data file */
Printf (" file open error ");
exit(0);
}
Have=fscanf (fp, "% d % d", & amp; Arrive. Temp., & amp; Temp. Treat);

Do {//agreement per cycle, processed a customer
If (link. Front==NULL& & Have==2)
{//waiting queue is empty
Dwaite +=temp. Arrive - clock;
Clock=temp. Arrive;
The EnQueue (& amp; The link, temp);
Have=fscanf (fp, "% d % d", & amp; Arrive. Temp., & amp; Temp. Treat);
}
DeQueue (& amp; The link, & amp; Curr);
count++;
Cwaite +=clock - curr. Arrive;
Finish=clock + curr. Treat;
While (have==2 & amp; & Finish> Temp. Arrive)
{
The EnQueue (& amp; The link, temp);
Have=fscanf (fp, "% d % d", & amp; Arrive. Temp., & amp; Temp. Treat);
}
Clock +=temp. Treat;
} while (have==2 | | link. The front!=NULL);
Printf (" service personnel of the total idle time: % d average waiting time and customer: % d ", dwaite, cwaite/count);
The fclose (fp);
return 0;
}

CodePudding user response:

 if ((fp=fopen (" Fname ", "r"))==NULL) {/* open data file */

This sentence has a problem, to:
 if ((fp=fopen (Fname, "r"))==NULL) {/* open data file */


You write the code, is to open the file named Fname file, not the filename you input, because the variables Fname deposit is the file path string;

CodePudding user response:

But still won't do, in fact, I copied the file path, then the Debug an Assertion Failed, big trouble you again, thank you

CodePudding user response:

The
reference 1/f, confident boy reply:
 if ((fp=fopen (" Fname ", "r"))==NULL) {/* open data file */

This sentence has a problem, to:
 if ((fp=fopen (Fname, "r"))==NULL) {/* open data file */


You write the code, is to open the file named Fname file, not the filename you input, because the variables Fname deposit is the file path string;
but still won't do, in fact, I copied the file path, then the Debug an Assertion Failed, big trouble you again, thank you
  • Related