CodePudding user response:
Your code? How can map content positioning problem?CodePudding user response:
An array, the subscript to 1CodePudding user response:
#include#include
#include
#include
//# define LEN1 sizeof (struct veg1) to LEN represents the struct student types of data length
Typedef struct information1//vegetables basic information
{
Int num1.//order number
Int num2;//classification code
Char nutrition [100].//nutrition
char name[20];//vegetable name
} information1;
Typedef struct information2//vegetable information
{
int num;//classification number
Int area;//vegetable growing area of
Int weight;//vegetables gain weight
Int year;//harvest year
char name[20];//vegetable name
} information2;
Typedef struct veg1/kind/subordinate categories of vegetables type
{
Int flag;//used to mark the unit has a visit
Struct information1 info;//structure of vegetable data domain
Struct veg1 * next;
} veg1;
Typedef struct veg2//used for vegetable planting information table structure
{
Struct information2 plant_info;//structure of vegetable data domain
Struct veg2 * next;
} veg2;
Typedef struct kind
{
int num;
Char kind_name [20].//type name
Struct kind * right;//equal categories
Struct veg1 * down;//subordinate subclass
} kind;
Kind * creat_trunk ();//create categories of main chain
Veg1 * sorting_line (FILE *);//add a sort main chain, used for basic information in the table, sorting and vegetable import categories of main chain
Void insert_veg (kind *, FILE *);//to the main chain add vegetables
Void the save (veg1 *, FILE *);
Char * split (char *, char *);
//main chain add
Kind * creat_trunk ()
{
int i;
Struct kind * head;
P1, struct kind * * (p2);
Head=(struct kind *) malloc (sizeof (kind));//header blank nodes, can not the assignment, or assign a use less than the value of the
The p2=head;
For (I=1; I & lt; 6; I++)
{
P1=(struct kind *) malloc (sizeof (kind));
P1 - & gt; Num=I;
P1 - & gt; Right=NULL;
P1 - & gt; The down=NULL;
If (I==1)
Strcpy (p1 - & gt; Kind_name, "root");
Else if (I==2)
Strcpy (p1 - & gt; Kind_name, "the fruit vegetable");
Else if (I==3)
Strcpy (p1 - & gt; Kind_name, "melon");
Else if (I==4)
Strcpy (p1 - & gt; Kind_name, "leaf vegetables");
Else if (I==5)
Strcpy (p1 - & gt; Kind_name, "bugs");
The p2 - & gt; Right=p;
P1 p2=;
}
The p2 - & gt; Right=NULL;
Return (the head);//return the head pointer
}
//plant insert
Void insert_veg (fp) kind * head, the FILE *//creat function: the return value is a pointer to the structure of the student body
{
Kind * p;
int i;
Char buffer [40].
Token, char * * STR;//STR entire rows of data from the buffer, token used to store information;
Char delim [2]=", ";
P1 veg1 * and * p2 [6];//p1 to create a new node, the p2 is used to record every kinds of traversal to the current node;
P=the head - & gt; Right;
For (I=1; I & lt; 6; I++)
{
The p2 [I]=(struct veg1 *) malloc (LEN1);//each column has a header blank nodes;
The p2 [I] - & gt; Next=NULL;
P - & gt; The down=p2 [I];
P=p - & gt; Right;
}
The fseek (fp, 69 l, SEEK_CUR);//from the second line of the form read
While ((STR=the fgets (buffer, sizeof (buffer), fp))!=NULL)
{
P=the head - & gt; Right;
Token=split (STR, delim); First, don't take//
For (I=1; I & lt; 6; I++)
{
Token=split (NULL, delim);
If (token [0]!='\ 0')
{
P1=(struct veg1 *) malloc (LEN1);
Strcpy (p1 - & gt; Info. Name, token);
P1 - & gt; Flag=0;
P1 - & gt; Next=NULL;
The p2 [I] - & gt; Next=p;
The p2 [I]=p;
}
}
P=p - & gt; Right;
}
}
//string segmentation function similar to strtok, pay attention to when we have n separator is n + 1 data, this function will be able to have the n + 2 output, the final output is NULL
Char * split (char * strToken, char * strDelimit)
{
Char * p;
Char * pd;
The static char * ps;
If (strToken!=NULL)
{
Ps=strToken;
While ((* ps!='\ 0') & amp; & (* ps! ))='\ n'
{
Ps++;
}
* ps='X';//X as the identifier, help the circulation end
Ps++;
* ps='\ 0';
Ps=strToken;
}
P=ps;
While (* ps!='\ 0')
{
Pd=strDelimit;
While ((* pd!='\ 0') & amp; & (* pd!=* ps))
Pd++;
If pd==(* * ps)
{
* ps='\ 0';
Ps++;
return p;
}
The else
Ps++;
}
If (* (ps - 1)=='X')
{
* (ps - 1)='\ 0';
return p;
}
return NULL;
}
//add a sort main chain, used for basic information in the table, sorting and vegetable import categories of main chain
Veg1 * sorting_line (fp) FILE *
{
Cur veg1 * head, *, * p;
Char buffer [500].
Token, char * * STR;//STR entire rows of data from the buffer, token used to store information;
Char delim [2]=", ";
The head=(struct veg1 *) malloc (LEN1);//header blank nodes;
Cur=head;
Fseek (fp, 35 l, SEEK_CUR);//from the second line of the form read
While ((STR=the fgets (buffer, sizeof (buffer), fp))!=NULL)
{
P=(struct veg1 *) malloc (LEN1);
Token=split (STR, delim);//import total sorts,
P - & gt; Info. Num1=atoi (token);
Printf (" % d ", p - & gt; Info. Num1);
Token=split (NULL, delim);//import vegetables name
Strcpy (p - & gt; Info. Name, token);
Printf (" % s ", p - & gt; Info. Name);
Token=split (NULL, delim);//import vegetables category codes
P - & gt; Info. Num2=atoi (token);//string integer function atoi
Printf (" % d \ n ", p - & gt; Info. Num2);
Token=split (NULL, delim);//import nutrients
Strcpy (p - & gt; Info. Nutrition, token);
Cur - & gt; Next=p;
Cur=p;
P - & gt; Next=NULL;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull