Debug to find out where the problem occurs
#include <stdlib.h> #include "Orderfist.h" status insertlist_sq (SqList l[])/* Insert an element in the list */{int32 i32osm = 1; UINT32 insert_position = 0U, Insert_data = 0U, u32i = 0U, u32j =0u;/* defines an unsigned location for inserting variables, data variables, and loop body variables */i32osm = osm_printf ("Please Lose Enter the position to be inserted (non-negative) and data: ");/* Prompt to enter the place */insert_position = Scanf_for ();/* Input the location to be inserted */insert_data = Scanf_for ();/* Enter the inserted data */l-& gt;u32length++;/* the length of the static table after insertion has been increased by a */for (u32j = l->u32length; u32j > (insert_position-1u), u32j--)/* After the insertion of the position for each The number is moved backward by one using the Loop body */{(L + u32j)->elem = ((L + u32j)-1U)->elem;/* moves the data position after the insertion point backward by one */} ((L + insert_position)-1U)-& Gt;elem = insert_data;/* assigns the input data to the insertion position data, before the insertion position is unchanged */for (u32i = 0U; u32i < l->u32length; u32i++)/* Use the loop body to print the data */{if (0U! = (L + u32i)->elem)/* detects the validity of incoming parameters */{I32OSM = osm_printf ("%d", (l+u32i)->elem);/* All print out */}}return 0U ;}
The l->u32length++; here is always 1 and no value is passed. It's always the same as 0 when it's initialized.
The question now is how to solve the l->u32length++ that will create the function through the assignment of the main function to the insertion function
Use structure pointers as function parameters for efficiency: When you need to protect the data, prevent accidental changes to the pointer const qualifier. Passing structure values is the most common method of handling small structures.
Issues that occur when you create a sequential table