نقل قول:
متاسفانه باز هم درست نشد:41:
Printable View
نقل قول:
متاسفانه باز هم درست نشد:41:
چرا درسته. منم که بر خلاف حرفهایی که میزنم سورس کد رو برای شما گذاشتم. تستش هم کرده بودم و کاملا درست کار میکرد. برنامه قبلی شما اصلا segmentation fault میداد. الان چه پیغام خطایی میگیرید که کار نمیکنه؟
سلامنقل قول:
دقیقا همون مشکل قبلی رو داره! اضافه میکنه ولی نه سرچش کار میکنه نه لیست کردنش؟
نقل قول:
کد کامل این هست:
[html]
#include <cstdlib>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
struct student
{
char name[20];
char family[25];
int id;
student *next;
};
student *first, *last;
void search(int id)
{
student *temp=new student;
int find;
temp=first;
while(temp!=NULL)
{
if (id==temp->id)
{
cout << temp->id << endl;
cout << temp->name << endl;
cout << temp->family << endl;
find=1;
break;
}
else
{
find=0;
temp=temp->next;
}
}
if (find==0)
cout << "not find record" << endl;
}
void input()
{
student *temp=new student;
cout << "plese enter the id : " << endl;
cin >> temp->id;
cout << "plese enter the name : " << endl;
cin >> temp->name;
cout << "plese enter the family : " << endl;
cin >> temp->family;
temp->next=NULL; // last element always points to NULL
if (first==NULL)
first=temp;
else
last->next=temp;
last=temp;
}
void output()
{
cout << "\nALL LIST\n\n";
student *temp=new student;
temp=first;
while (temp!=NULL)
{
cout << endl;
cout << temp->id << endl;
cout << temp->name << endl;
cout << temp->family << endl;
cout << "*************************************";
temp=temp->next;
}
cout << "\nend of record\n\n" << endl;
}
int main(int argc, char *argv[])
{
int stat;
first=NULL;
last=NULL;
while (1)
{
cout << "\n***************************************" <<endl;
cout << "num 1 for input data " << endl;
cout << "num 2 for list data " << endl;
cout << "num 3 for search data " << endl;
cout << "num 4 for exit" << endl;
cout << "***************************************" <<endl ;
cin >> stat;
switch(stat)
{
case 1:
input();
break;
case 2:
output();
break;
case 3:
int key;
cout << "plese enter id for search : " ;
cin >> key;
search(key);
break;
case 4:
exit(0);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
[/html]مطمئن هستم کار میکنه. قبلا هم همین بود، منتنها من فقط قسمتهایی که فکر میکردم مهم باشه گذاشته بودم.