Home > Back-end >  Dear bosses, I kneel, fwrite write array structure, data after why frean read it
Dear bosses, I kneel, fwrite write array structure, data after why frean read it

Time:09-19

#include
#include
#include
# define NUMBER 1000;//can entry goods total
Void fun1 () {
printf("\n");
Int o;
Int choice;
int i=0;
Typedef struct good//a single commodity structure
{
Int number;//product id
Char name [4]={' \ 0 ', '\ 0', '\ 0', '\ 0'};//trade name
Char inprice [4]={' \ 0 ', '\ 0', '\ 0', '\ 0'};//commodity purchase price
Char outprice [4]={' \ 0 ', '\ 0', '\ 0', '\ 0'};//sales prices
Int Numbers;//commodity inventories
} GOOD;
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
{
Goods. Number=0;
Goods. Number +=1;

Printf (" please enter the name of the warehousing goods \ n ");//trade name
The scanf (" % s ", & amp; Goods. Name);
getchar();

Printf (" please enter the commodity stock price \ n ");//commodity purchase price
The scanf (" % s ", & amp; Goods. Inprice);
getchar();

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);

O=fwrite (& amp; Goods, sizeof (GOOD), 1, fp);//the information written to the file
Printf (" % d \ n, o);

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;
Int b, j, xuanze=0;
int count;
Int m=0;
Int c=0;

Typedef struct good//a single commodity structure
{
Int number;//product id
Char name [10].//trade name
Char inprice;//commodity purchase price
Char outprice;//sales prices
Int Numbers;//commodity inventories
} GOOD;
//GOOD * p;
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, sizeof (GOOD), 1, fp);//read from the file all the goods of data
If (count==1)
M++;
} while (! The feof (fp));//determine whether read end-of-file
fclose(fp);
Printf (" the system is ready! \n");

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 (" ok ");
}
The else
Printf (" % d ", goods [I] number);

}



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:

Binary, speaking, reading and writing, speaking, reading and writing structure, to use! Open the way to use ab +

CodePudding user response:

Began to use the binary, then read it out information corresponding, convert TXT, with some very hot very hot words

CodePudding user response:

 # include & lt; Stdio. H> 
#include
#include

//# define NUMBER 1000.//can entry goods total # why want to add a semicolon
# define total NUMBER/1000//entry goods

Typedef struct good//a single commodity structure
{
Int number;//product id
Char name [32].//={' \ 0 ', '\ 0', '\ 0', '\ 0'};//trade name
Char inprice [4].//={' \ 0 ', '\ 0', '\ 0', '\ 0'};//commodity purchase price
Char outprice [4].//={' \ 0 ', '\ 0', '\ 0', '\ 0'};//sales prices
Int Numbers;//commodity inventories
} GOOD;

Void fun1 () {
printf("\n");
Int o;
Int choice;
int i=0;
/*
Typedef struct good//a single commodity structure
{
Int number;//product id
Char name [4].//={' \ 0 ', '\ 0', '\ 0', '\ 0'};//trade name
Char inprice [4].//={' \ 0 ', '\ 0', '\ 0', '\ 0'};//commodity purchase price
Char outprice [4].//={' \ 0 ', '\ 0', '\ 0', '\ 0'};//sales prices
Int Numbers;//commodity inventories
} GOOD;
*/
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
{
Goods. Number=0;
Goods. Number +=1;

Printf (" please enter the name of the warehousing goods \ n ");//trade name
//the scanf (" % s ", & amp; Goods. Name);
The scanf (" % s ", goods name).
//getchar ();

Printf (" please enter the commodity stock price \ n ");//commodity purchase price
//the scanf (" % s ", & amp; Goods. Inprice); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related