#pragma once這是我的頭檔案
#include<iostream>
using namespace std;
#include <string>
#include <istream>
#include <stdlib.h>
#include <malloc.h>
#include <stdio.h>
#define LENTH sizeof(struct teacher)
//fuction
void SpringTeacherInformation(struct teacher* p);
struct teacher* Creat();
//value
int Order(string *order);
string order;
int LenthOfList = 0;
struct student
{
string name;
float score;
};
struct teacher
{
string name;
struct student stu[4];
struct teacher* next;
};
#include "head.h"
int main()
{
cout << LENTH << endl;
cout << "歡迎進入錄入系統!" << endl << endl;
while (1)
{
cout << "是否輸入資料?";
if (Order(&order) == 1)
{
Creat();
};
}
cout << "系統結束..." << endl;
system("pause");
return 0;
}
teacher* Creat()
{
static teacher* head;
static teacher* p1 = nullptr;
static teacher* p2 = nullptr;
p1 = (struct teacher*)malloc(LENTH);
p2 = p1;
int i;
//創建第一個資料鏈表
if (p1==nullptr)
{
cout << "創建資料失敗,請稍后再試..." << endl;
return nullptr;
}
else
{
cout << p1<< endl;
head = nullptr;
cout << "請輸入老師姓名: ";
scanf_s("%s", &(p1->name));
最后一行 “scanf_s...”出現例外
“0x7A9DE63C (ucrtbased.dll)處(位于 dome.exe 中)引發的例外: 0xC0000005: 寫入位置 0x01252000 時發生訪問沖突。
”
我自己練習表鏈:
我自己推測例外原因是 mallco 申請記憶體失敗 或者 是記憶體沒有訪問權限,可是記憶體應該驗證是申請成功的。。。
倒底是什么原因呀,我是才學習C++小白,望大牛解答~~~
uj5u.com熱心網友回復:
c++的話用new申請記憶體吧,另外p1->name是字串,scanf時并不需要&符號cout << p1<< endl;這句不知道是什么意思,輸出它有什么作用嗎。c和c++陳述句最好不要混用,要不用c要不用c++,你這一會cout一會scanf讓人看著很難受
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/235177.html
標籤:C++ 語言
上一篇:字符陣列輸出問題
下一篇:給一個物件陣列怎么賦值?
