リストの最後にデータを挿入しようとしていますが、動作していません。実行時に例外が発生します。このコードでリンクリストに問題がありますが、デバッガはテンポラリメモリにアクセスできません。
struct gradeNode *newNode = (struct gradeNode*)malloc(sizeof(struct gradeNode));
assert(newNode != NULL);
strcpy(newNode->courseName, courseName); // copying the course name
newNode->next = NULL;
struct gradeNode *temp = students[i].gradelist->head; // a temp
// here is the problem: the debugger says ecxeption, can't access memory
while (temp->next != NULL)
{
temp = temp->next; // I can't get to here
temp->next = newNode;
}
[malloc()の返り値をCでキャストしない理由についてのこのディスカッションを参照してください。](https://stackoverflow.com/q/605845/2173917) –
'students [i]です。 gradelist-> head'を正しく初期化しましたか?これはいつ起こるのですか? 'temp'はヌルか無効なポインタですか? [最小限の、完全で検証可能な例](http://stackoverflow.com/help/mcve)を作成してください。そして、[良い質問をする方法を読む](http://stackoverflow.com/help/how-to-ask)に時間を割けてください。 –
@loay tempはNULLに等しいと思われます。 –