Lỗi Stopped working trong C

Anh, chị ai giúp xem code của em lỗi chỗ nào mà khi chạy nó bị lỗi .exe have stopped work.
Code em đây ạ:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
// Dinh nghia struct de luu thong tin sinh vien
typedef struct
{
	char name[40];
	char account[15];
	char subject[15];
	int score;
}STUDENT, *PSTUDENT;
//khai bao danh sach lien ket don
struct Node
{
	STUDENT n;
	Node *pNext;
};

struct SLL
{
	Node *pHead;
	Node *pTail;
};
//khoi tao danh sach lien ket don
void initSLL(SLL &list)
{
	list.pHead = list.pTail = NULL;
}
//In danh sach ra man hinh
void output (STUDENT x)
{
    printf("\n%s\t\t%s\t\t%s\t\t%d",x.name,x.account,x.subject,x.score);
}
void viewSLL (SLL list)
{
    Node *pNode;
    pNode=list.pHead;
    while(pNode!=NULL)
    {
        output(pNode->n);
        pNode=pNode->pNext;
    }
}
//Tao 1 nut moi
Node *newNode(STUDENT k)
{
	Node *pNode;
	pNode = (Node*)malloc(1 * sizeof(Node));
	//if (!pNode)
	//{
	//	return NULL;
	//}
	pNode->n = k;
	pNode->pNext = NULL;
	return pNode;
}
//Chen 1 nut vao cuoi danh sach
void AddLast (SLL &list, Node *pNode)
{
    //if(list.pHead==NULL)  
	//	list.pHead=list.pTail=pNode;
    //else
    //{
        list.pTail->pNext=pNode;
        list.pTail=pNode;
    //}
}
//Nhap
void input (STUDENT k)
{
    printf("\nNhap ten sinh vien: ");  fflush(stdin); gets(k.name);
    printf("\nNhap account: ");  fflush(stdin); gets(k.account);   
    printf("\nNhap mon hoc: "); fflush(stdin); gets(k.subject);
    printf("\nNhap diem: "); scanf("%d",&k.score);
}
//Search
void Search (SLL list)
{
	STUDENT m;
    Node *pNode;
    int dem=0;
    char a[15];
    printf("\nNhap account sv can tim: ");
    fflush(stdin);
    gets(a);
    pNode=list.pHead;
    while (pNode!=NULL)
    {
        if(strcmp(a,pNode->n.account)==0)      dem++;
        pNode=pNode->pNext;
    }
    if(dem!=0)
    {
    	m=pNode->n;
        printf("\nTim thay sv: ");
		printf("\n%s\t%s\t%s\t%d",m.name,m.account,m.subject,m.score);
    }
    else
	    printf("\nKo tim thay.");
}
//Delete
void Delete (SLL &list)
{
    Node *pNode, *qNode;
    char a[15];
    pNode=list.pHead;
    qNode=NULL;
    printf("\nNhap account can xoa: ");
    fflush(stdin);
    gets(a);
    while (pNode!=NULL)
    {
        if(strcmp(a, pNode->n.account)==0)    break;
        else printf("\nKo co sv can xoa.");
        qNode=pNode;
        pNode=pNode->pNext;
    }
    if(qNode!=NULL)
    {
        if(pNode!=NULL)
        {
            qNode->pNext=pNode->pNext;
            delete (pNode);
            if(pNode==list.pTail)
				list.pTail=qNode;
            delete(pNode);
        }
    }
    else
    {
        list.pHead=pNode->pNext;
        delete(pNode);
        if(list.pHead==NULL)  list.pTail=NULL;
    }
}
int main()
{
	SLL list;
	Node *pNode;
	STUDENT k;
	int a;
	initSLL(list);
	do
	{
		printf("*************************************************\n");
		printf("*\t\tSTUDENT MANAGEMENT\t\t*\n");
		printf("*************************************************\n");
		printf("1.Insert student\n");
		printf("2.Delete student\n");
		printf("3.Search student base on account\n");
		printf("4.Show student imformation\n");
		printf("5.Save student imformation to STUDENT.LOG file\n");
		printf("6.EXIT\n\n");
		printf("Which option would you like?\n");
		scanf("%d",&a);
		switch(a)
		{
			case 1:
				{
					STUDENT chen;
					printf("Nhap thong tin sinh vien can insert:\n");
					input(chen);
					Node *t = newNode(chen);
					AddLast(list,t);
					printf("Danh sach sau khi them: \n");
					viewSLL(list);
					break;
				}
			case 2:
				{
					Delete(list);
					printf("Danh sach sau khi xoa: \n");
					viewSLL(list);
					break;
				}
			case 3:
				{
					Search(list);
					break;
				}
			case 4:
				{
					printf("Danh sach sinh vien: \n");
					viewSLL(list);
					break;
				}
			default:printf("Nhap lai:\n");		
		}
	} while(a!=6);
	getch();
}

Bạn đang dùng C hay C++ vậy bạn

Mình đang học cả C lần C++. format ’ nghĩa là ntn ạ, mình không hiểu

Là như thế này

```
code của bạn
```

Bạn vừa format code rồi nên thôi.

Bạn có thể chỉ rõ ngôn ngữ đang dùng để làm cái này được không. Tại trông nó hơi lạ

tìm giúp mình bị lỗi gì mà build vẫn được mà chạy thì toàn stopped working. Mình tìm từ chiều đến giờ :((

Mình dùng ngôn ngữ C nhá.

bạn lưu là *.cpp mà sao nó có thể biên dịch cái ở dưới được

void initSLL(SLL &list)

Mình tạo file .cpp nhưng viết bằng C. Mình dùng dev C ạ

Vậy sao bạn không debug thử xem lỗi ở đâu

@@ Mình không biết debug :)))

Google bebug Dev C nha bạn.

1 Like

ok. cảm ơn ban. mình thử xem

Hi Nguyễn Văn Đức.
Bạn up thêm cả màn hình lỗi lên nữa cho mọi người dê tìm.

Mà bạn cũng nên tránh kiểu nửa code C nửa code C++ thế không là dễ bị “tẩu hỏa nhập ma”

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?