01/10/2018, 10:45
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("
%s %s %s %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("
Nhap ten sinh vien: "); fflush(stdin); gets(k.name);
printf("
Nhap account: "); fflush(stdin); gets(k.account);
printf("
Nhap mon hoc: "); fflush(stdin); gets(k.subject);
printf("
Nhap diem: "); scanf("%d",&k.score);
}
//Search
void Search (SLL list)
{
STUDENT m;
Node *pNode;
int dem=0;
char a[15];
printf("
Nhap 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("
Tim thay sv: ");
printf("
%s %s %s %d",m.name,m.account,m.subject,m.score);
}
else
printf("
Ko tim thay.");
}
//Delete
void Delete (SLL &list)
{
Node *pNode, *qNode;
char a[15];
pNode=list.pHead;
qNode=NULL;
printf("
Nhap account can xoa: ");
fflush(stdin);
gets(a);
while (pNode!=NULL)
{
if(strcmp(a, pNode->n.account)==0) break;
else printf("
Ko 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("*************************************************
");
printf("* STUDENT MANAGEMENT *
");
printf("*************************************************
");
printf("1.Insert student
");
printf("2.Delete student
");
printf("3.Search student base on account
");
printf("4.Show student imformation
");
printf("5.Save student imformation to STUDENT.LOG file
");
printf("6.EXIT
");
printf("Which option would you like?
");
scanf("%d",&a);
switch(a)
{
case 1:
{
STUDENT chen;
printf("Nhap thong tin sinh vien can insert:
");
input(chen);
Node *t = newNode(chen);
AddLast(list,t);
printf("Danh sach sau khi them:
");
viewSLL(list);
break;
}
case 2:
{
Delete(list);
printf("Danh sach sau khi xoa:
");
viewSLL(list);
break;
}
case 3:
{
Search(list);
break;
}
case 4:
{
printf("Danh sach sinh vien:
");
viewSLL(list);
break;
}
default:printf("Nhap lai:
");
}
} while(a!=6);
getch();
}
Bài liên quan
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
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
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.
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”