1. The same kind of goods enter the second (that is, to increase the number of the original goods), the program in question did not increase the number of
2. The outbound function can't run, only the input number is automatically end the system
3. How will the warehouse in and out of the log records in the file
In the comments (code)
Thank you very much!!!!!!
CodePudding user response:
Void input (){
Struct Info Info;
The FILE * fp1, * fp2;
Char f, ch [10];
Fp1=fopen (1. "dat", "rb");//existing read-only binary file
Fp2=fopen (2. "dat", "wb +");//a new file, allow to read and write, store the updated cargo information
Printf (" please enter the product number: ");
The scanf (" % s ", & amp; Ch);
while(! Feof (fp1))//finished goods into the library in the fp1
{
If (fread (& amp; Info, sizeof (info), 1, fp1))//can be read from the fp1 one object to the info
{
If (STRCMP (ch, info. Num)==0)//if the goods already exists
{
Printf1 ();
Printf2 (info);//check the current inventory
Printf (" please enter the number of goods: ");
The scanf (" % d ", & amp; Info. Amount);
printf("\n");
Fwrite (& amp; Info, sizeof (info), 1, fp2);//update the inventory information
while(! The feof (fp1))
{
If (fread (& amp; Info, sizeof (info), 1, fp1))
Fwrite (& amp; Info, sizeof (info), 1, fp2);
}
break;
}
}
The else//new items
{
Printf (" please enter the new information: \ n ");
Printf (" please enter the name of goods: ");
The scanf (" % s ", & amp; Info. Name);
printf("\n");
Printf (" please enter the number of goods: ");
The scanf (" % d ", & amp; Info. Amount);
printf("\n");
Printf (" please enter the product number: ");
The scanf (" % s ", & amp; Info. Num);
Fwrite (& amp; Info, sizeof (info), 1, fp2);//update the inventory information
}
}
The fclose (fp1);
The fclose (fp2);
Remove (1. "dat");
Rename (2. "dat", "1. Dat");
Printf (" press any key to return to the menu ");
Getchar ();
System (" CLS ");
menu();
}
CodePudding user response:
Void the output ()//outbound function{
Struct Info Info;
The FILE * fp1, * fp2;
Int a;
Char ch [20].
Printf (" please enter need the serial number of outbound ");
The scanf (" % s ", ch);
while(! The feof (fp1))
{
If (fread (& amp; Info, sizeof (info), 1, fp1))
If (STRCMP (ch, info. Num)==0)//
the existence of the goods{
Printf1 ();
Printf2 (info);
Printf (" please enter the number of outbound ");
The scanf (" % d ", & amp; A);
If (a<=info. Amount)//whether the inventory is greater than demand
{
Info. Amount -=a;
Fwrite (& amp; Info, sizeof (info), 1, fp2);
Printf (" outbound success! \n");
If (info. Amount==0) {
Zero (ch);
}//inventory is zero to remove the goods
}
The else
{
Printf (" insufficient goods! Your request was refused \ n ");
}
while(! The feof (fp1))
{
If (fread (& amp; Info, sizeof (info), 1, fp1))
Fwrite (& amp; Info, sizeof (info), 1, fp2);
break;
}
}
The else
Fwrite (& amp; Info, sizeof (info), 1, fp2);
}
The fclose (fp1); The fclose (fp2);
Remove (1. "dat");
Rename (2. "dat", "1. Dat");
System (" pause ");
Printf (" press any key to return to the menu ");
Getchar ();
System (" CLS ");
menu();
}
Void zero (char ch [10])//delete the goods information
{
Struct Info Info;
The FILE * fp1, * fp2;
while(! The feof (fp1))
{
If (fread (& amp; Info, sizeof (info), 1, fp1))
{
Printf (" deleted successfully! \n");
}
}
The fclose (fp1);
The fclose (fp2);
Remove (1. "dat");//delete
Rename (2. "dat", "1. Dat");
Printf (" press any key to return to the menu ");
Getchar ();
System (" CLS ");
menu();
}
CodePudding user response:
void input ()
{
Struct Info Info;
The FILE * fp1, * fp2;
Char f, ch [10];
Fp1=fopen (1. "dat", "rb");//existing read-only binary file
Fp2=fopen (2. "dat", "wb +");//a new file, allow to read and write, store the updated cargo information
Printf (" please enter the product number: ");
//the scanf (" % s ", & amp; Ch);
The scanf (" % s ", ch);
while(! Feof (fp1))//finished goods into the library in the fp1
{
If (fread (& amp; Info, sizeof (info), 1, fp1))//can be read from the fp1 one object to the info
{
If (STRCMP (ch, info. Num)==0)//if the goods already exists
{
Printf1 ();
Printf2 (info);//check the current inventory
Printf (" please enter the number of goods: ");
The scanf (" % d ", & amp; Info. Amount);
printf("\n");
Fwrite (& amp; Info, sizeof (info), 1, fp2);//update the inventory information
while(! The feof (fp1))
{
If (fread (& amp; Info, sizeof (info), 1, fp1))
Fwrite (& amp; Info, sizeof (info), 1, fp2);
}
break;
}
}
The else//new items
{
Printf (" please enter the new information: \ n ");
Printf (" please enter the name of goods: ");
The scanf (" % s ", & amp; Info. Name);
printf("\n");
Printf (" please enter the number of goods: ");
The scanf (" % d ", & amp; Info. Amount);
printf("\n");
Printf (" please enter the product number: ");
The scanf (" % s ", & amp; Info. Num);
Fwrite (& amp; Info, sizeof (info), 1, fp2);//update the inventory information
}
}
The fclose (fp1);
The fclose (fp2);
Remove (1. "dat");
Rename (2. "dat", "1. Dat");
Printf (" press any key to return to the menu ");
Getchar ();
System (" CLS ");
menu();
}
There is something wrong with the input function of the building Lord didn't see?
The outermost layer is judge fp1, but the inner fp1 while or judgment, the else in another judgment fp1 and while loop input have what relation?
Suggest the original poster is straightened out logic,