473,385 Members | 1,472 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

my list error!!

wbgxx
6
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. using namespace std;
  3. class list
  4. {
  5. public:
  6.     int number,score;
  7.     char name[10];
  8.     class list*next;
  9. };
  10.  
  11. void create(list* head)
  12. {
  13.     list* p=head;
  14.     while(1)
  15.     {
  16.         list* pp=new node;
  17.         if(!pp)
  18.         {
  19.             cout<<"erroe"<<endl;
  20.             exit(1);
  21.         }
  22.         cout<<"Please input the student ID:";
  23.         cin>>pp->number;
  24.         if(pp->number==0)
  25.             break;
  26.         else
  27.         {
  28.  
  29.             cout<<"Pleast input the studnet name";
  30.             cin>>pp->name;
  31.             cout<<"Please input score:";
  32.             cin>>pp->score;
  33.             p->next=pp;
  34.             p=pp;
  35.         }
  36.  
  37.     }
  38. }
  39.  
  40. void show(list* head)
  41. {
  42.     list* ptr=head;
  43.     cout<<"\n --  STUDNET  ---"<<endl;
  44.     cout<<"ID\tNAME\tscore\n============================"<<endl;
  45.     while(ptr!=NULL)
  46.     {
  47.         cout<<ptr->number<<"\t"<<ptr->name<<"\t"<<ptr->score<<endl;
  48.         ptr=ptr->next;
  49.  
  50.     }
  51. }
  52.  
  53. int main()
  54. {
  55.     list* head=NULL;
  56.     create(head);
  57.     show(head);
  58.     return 0;
  59. }
Jan 21 '10 #1
3 1375
wbgxx
6
there is a error in runtime
Jan 21 '10 #2
weaknessforcats
9,208 Expert Mod 8TB
It looks like head in NULL in main() after the return from create. Then you use the null pointer with the -> operator in show and die right there.

You need to pass the address of head to create. The argument to create should be list** so you can put the address of the created node into head by using *head = new node in create.

Do you have a debugger you can use? Usually you can step through code and see exactly where it fails.
Jan 21 '10 #3
johny10151981
1,059 1GB
In line 56 you have called create function with variable head which is null

In line 13 you have assigned
p = head
which mean p is null;
but in line 33 you did
p->next=pp;
but still p is null. You cant do that. Try allocate some memory.

But you should also check your logic. Cause in line 34 you did
p=pp;

So re-think what do want to do...
I think your logic will be something like that... First before line 56 allocate some memory for head(use malloc).

in the function do something like that (or better you think)
while()
{
...
some logic to control loop.
...
pp = new ...();
p->next=pp;
p->...=your_data();
}while()

above logic is not complete. You better complete yourself. (I am not that good)

Best Regards,
JOHNY
Jan 21 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Kain0o0 | last post by:
Hello , thanks for any help in advance. Im writing some code for a c++ class and the proffessor wants us to implement a list template using arrays. I thought this would be an easy task but have...
4
by: PRadyut | last post by:
hi, i have written a function in adding a node to the linked list but this only adds "1" to the list as i get in the output I'm using borland c++ compiler The code...
0
by: Andrew Luke | last post by:
Hi There, I'm trying to get a listing of shares from a server. The server is a linux box running samba and LDAP for directory services (just for background info!) I have some code which I...
1
by: Plissken.s | last post by:
Hi I have a problem which result in a "corrupted double-linked list error", I would need some help in trouble shot this one: Here is a stack track: Thread (Suspended: Signal 'SIGABRT'...
2
by: Kaur | last post by:
Hi, I have a form Form1 that displays surveys. This form has a subform1 which displays questions related to a particular survey. This subform has a subsubform which displays subquestions for a...
5
by: Vv_vV | last post by:
Hi all, I try to call onchange a function and get "missing ) after argument list" error Probably systaxis issue Thanks in advance for any help! Code: var html = ""; var myurl =...
3
by: GavReynolds | last post by:
Hi All I usually create my flash programs in the old fashioned way (draw all the movie clips). However i have just recieved a project which involves 390 movie clips (all of which are little...
0
by: yosri2005 | last post by:
Hello, I'm sure many of you have seen the error message in the subject. I found quiet a few posts on the web regarding this issue, but the ones I saw mainly tackle this issue when you have a...
3
by: kevinkwh | last post by:
Hi, I'm an intern student and my boss told me to do porting from Linux c to Visual C++.When I built the coding, I found this error "unexpected in macro formal parameter list", here is the coding...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.