#include
#include
#include
Typedef struct good//a single commodity structure
{
Char name [4].
Char * inprice;
Char * outprice;
Int Numbers;//commodity inventories
} GOOD;
Void fun1 () {
printf("\n");
Int choice;
int i=0;
GOOD goods.
The FILE * fp.
Fp=fopen (" inventory list. TXT ", "a +");//open the file
If (fp==NULL)
{
Printf (" file open failed! \ n ");
}
Do//commodity information entry
{
Printf (" please enter the name of the warehousing goods \ n ");//trade name
The scanf (" % s ", goods name).
//getchar ();
Printf (" please enter the commodity stock price \ n ");//commodity purchase price
The scanf (" % s ", & amp; Goods. Inprice);
Printf (" please enter the commodity sale price \ n ");//sales prices
The scanf (" % s ", & amp; Goods. Outprice);
//getchar ();
Printf (" please input the number of inbound goods \ n ");//inventory quantity
The scanf (" % d ", & amp; Goods. Numbers);
Fwrite (& amp; Goods, sizeof (GOOD), 1, fp);//the information written to the file
Printf (" whether to continue the entry? (according to the Numbers 1 to 0 exit) ");//to judge whether or not to continue entry?
The scanf (" % d ", & amp; Choice);//read the user to select
//getchar ();//eat enter
}
While (choice==1);
fclose(fp);//close the folder
}
Void fun3 () {
Char names [10].//users buy goods name
int i=0;
Double f;
Int b, j, xuanze=0;
Int count, chioce;
Int m=0;
Int c=0;
Double sum=0;
GOOD goods [1000].
The FILE * fp.
Fp=fopen (" inventory list. TXT ", "a +");//open the file
If (fp==NULL)
{
Printf (" file open failed! \n");
}
The rewind (fp);//pointer position reset
Do
{
The count=fread (& amp; Goods [m], sizeof (GOOD), 1, fp);//read from the file all the goods of data
If (count==1)
{
Printf (" successfully read in the first % d \ n ", m + 1);
M++;
}
} while (! The feof (fp));//determine whether read end-of-file
fclose(fp);
Printf (" the system is ready! \n");
Do {
Printf (" please enter the name to buy goods: \ n ");
The scanf (" % s ", names);
getchar();
for(j=0; J
If (STRCMP (names, goods [c]. Name)!=0)
{
Xuanze=1;
}
c++;
}
If (xuanze!
=1)exit(0);
Printf (" please input the number of need to purchase a commodity \ n ");
The scanf (" % d ", & amp; B);
getchar();
If (b<=goods [I] enough//inventory Numbers)
{
Printf (" commodity purchase success!" );
}
F=atof (goods [I] outprice);
Printf (" % lf ", f);
The sum b +=f *;
Printf (" the need to continue to buy? (continue to buy 1, 0) \ n ");
The scanf (" % d ", & amp; Chioce);
getchar();
} while (chioce==1);
Printf (" clearing, please wait... \n");
Printf (" you need to pay total % 2 f yuan! \ n ", sum);
Printf (" thank you for your patronage, I wish you a happy life!" );
getchar();
}
//void main ()
Void main ()
{
Int choice;
While (1)
{
Printf (" \ n \ n \ n ");
Printf (" * * * * with * against * * *, * by product sale * * tube reason * * pin * * of * * * * \ n ");
Printf (" * * \ n ");
Printf (" * 1. Inventory table data entry * \ n ");
Printf (" * 2. The sales table data entry * \ n ");
Printf (" * * 3. Sales goods \ n ");
Printf (" * 4. The inventory table query * \ n ");
Printf (" * 5. Sales table query * \ n ");
Printf (" * 0. Exit * \ n ");
Printf (" * * \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" do choice (0 to 5) : ");
The scanf (" % d ", & amp; Choice);
The switch (choice)
{
Case: 0 exit (0);//header files define & lt; Stdlib. H> , the end of the program
Case 1: fun1 (); break;
Case 2://fun2 (); break;
Case 3: fun3 (); break;
Case 4://fun4 (); break;
Case 5://fun5 ();
break;
}
}
}
CodePudding user response:
The inprice and outprice into a character arrayCodePudding user response:
Just changed, performs the return value to the output atof, still can not continueCodePudding user response:
# include & lt; Stdio. H>
#include
#include
#include
Typedef struct good//a single commodity structure
{
Char name [32].
//char * inprice;
//char * outprice;
Char inprice [16].
Char outprice [16].
Int Numbers;//commodity inventories
} GOOD;
Void fun1 () {
printf("\n");
Int choice;
int i=0;
GOOD goods.
The FILE * fp.
Fp=fopen (" inventory list. TXT ", "a +");//open the file
If (fp==NULL)
{
Printf (" file open failed! \ n ");
}
Do//commodity information entry
{
Printf (" please enter the name of the warehousing goods \ n ");//trade name
The scanf (" % s ", goods name).
//getchar ();
Printf (" please enter the commodity stock price \ n ");//commodity purchase price
//the scanf (" % s ", & amp; Goods. Inprice);
The scanf (" % s ", goods. Inprice);
Printf (" please enter the commodity sale price \ n ");//sales prices
//the scanf (" % s ", & amp; Goods. Outprice);
The scanf (" % s ", goods. Outprice);
//getchar ();
Printf (" please input the number of inbound goods \ n ");//inventory quantity
The scanf (" % d ", & amp; Goods. Numbers);
Fwrite (& amp; Goods, sizeof (GOOD), 1, fp);//the information written to the file
Printf (" whether to continue the entry? (according to the Numbers 1 to 0 exit) ");//to judge whether or not to continue entry?
The scanf (" % d ", & amp; Choice);//read the user to select
//getchar (); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull