使用vs2019
#include <stdio.h>
#include<string>
#include <stdlib.h>
#include <conio.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define MAXSIZE 1000
typedef int Status;
typedef struct {
int no;
char name[50]; //book's name
float price;
}Book;
typedef struct {
Book* elem;
int length;
}SqList;
Status InitList(SqList& L)
{
L.elem = new Book[MAXSIZE];
L.length = 0;
return OK;
}
Status ListInsert(SqList& L, int i, Book book) {
if (i<1 || i>L.length + 1)
return ERROR;
if (L.length == MAXSIZE)
return ERROR;
for (int j = L.length - 1; j > i - 1; j--) {
L.elem[j + 1] = L.elem[j];
}
L.elem[i - 1] = book;
++L.length;
return OK;
}
Book SetBook() {
Book book;
int no=0;
char name[50]="";
float price=0.0;
printf("请输入no:\n请输入书名:\n请输入价格:\n");
scanf_s("%d", &book.no);
scanf_s("%s", &book.name,50);
scanf_s("%f", &book.price);
return book;
}
int main(){
SqList L;
InitList(L);
Book book=SetBook();
ListInsert(L, 2, book);
printf("%d", L.elem[2].no);
return 0;
}
调试的时候book能够得到我输入的值,但是到了ListInsert函数中,book没有赋值给L.elem[i-1],求大佬解答