Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Why do I have 85 of the exact same error with one module?

Hello all, I am having some problems with a LOT of errors, for this small module. Below is my code that I have so far, and the module called, modify causes 85 errors that are all the same - C:\Documents and Settings\ms219548\My Documents\Data\Linked_List.cpp(151) : error C2143: syntax error : missing ';' before '}'

When i comment out that module I only get 17 errors. those i haven't gotten to yet because I was just blown away by 85 errors.

The purpose of the program is to take input from a file and using pointers to store the info and manipulate it depending on the first number on the line.

Here is the full code,

#include<iostream>
#include<fstream>
using namespace std;

fstream instream;

struct node; //define the structure of the node
typedef node *node_ptr;

struct node{
int indicator;
char name[20];
int ssnum;
char address[25];
int phone;
node_ptr next;
};

node_ptr list, p, q, prev;

void get_node(node_ptr q);
void print_list(node_ptr list);
void modify(node_ptr list);
void delete_info(node_ptr list);
bool search(list, prev, p);

int main(){

int indicator;
node_ptr q;
list = NULL;

//reads the information in from an external file to a linked list
fstream instream;
instream.open("linked2.txt", ios::in);
while (!instream.eof())
{
instream >> indicator;

switch (indicator)
{
case 1: //indicator is 1
bool search(list, prev, p);
if (!found) // if the value is not in the list already, insert it
{
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
instream >> q->phone;
void get_node(node_ptr q);
}
break;

case 2: //indicator is 2
bool search(list, prev, p);
if (found) // if the value is already in the list, delete it
{
void delete_info(node_ptr list);
}
break;

case 3: //indicator is 3
bool search(list, prev, p);
if (found) // if the value is found, modify the phone number
{
void modify(node_ptr p);
}
break;

case 4: //indicator is 4
void print_list(node_ptr list);
break;

default:
break;
}
}
instream.close();

return 0;
}

void get_node(node_ptr q)
{
q = new node;
q->next = NULL;
}

//Indicator = 4 then we print out the info to a formatted table
void print_list(node_ptr list)
{
node_ptr p; //get a temporary pointer and initialize it to the
p = list; //address of the first node

while (p != NULL) //as long as there are more elements in the list
{
cout << "Name \t SS Number \t Address \t Phone Number \t\n";
cout << "___________________________________________________\n";
cout << p->name <<"\t"; //print out the contents of the data field
cout << p->ssnum <<"\t";
cout << p->address <<"\t";
cout << p->phone <<"\t";
p = p->next; //move to the next node
}
}

//HERE IS THE MODULE THAT IS GIVING ME THE PROBLEMS!!!!!!!!!
//HERE IS THE MODULE THAT IS GIVING ME THE PROBLEMS!!!!!!!!!
//HERE IS THE MODULE THAT IS GIVING ME THE PROBLEMS!!!!!!!!!
//
//Indicator = 3 then the person's telephone number is to be modified
void modify(node_ptr q)
{
q = p;
q->phone = new phone;
}

//Indicator = 2 then the person's information is to be deleted from the linked list
void delete_info(node_ptr q)
{
q = p;
delete q;
q = NULL;
}

//Search routine to determine if information is already in the linked list
bool search(list, prev, p)
{
bool found;
prev = NULL;
p = list;
while ((p!=NULL) && (p->name != name))
{
prev = p;
p = p->next;
if (p == NULL)
found = false; //name not found
else
if (p->name != name)
found = false; //name not found
else
found = true; //name found
}
return (found);
}
[4417 byte] By [IBMT43] at [2007-11-11 9:59:31]
# 1 Re: Why do I have 85 of the exact same error with one module?
I found those errors :
>bool search(list, prev, p);
you cant initialize a function with variabels name; u must use their types.
correction : bool search(node_ptr, node_ptr, );

> case 1: //indicator is 1
bool search(list, prev, p);
U mustn't call a function using the return as parameter "Bool"
correction : search(list, prev, p);

the same for all cases ..

>bool search(list, prev, p)
u must specify the type of variables in the function header .
correction : bool search(node_ptr list, node_ptr prev, node_ptr p)

>if (!found)
u can't use a local variabel in an external function .
the variable is decleared in search() function and u want to use it in main() function .
correction : declare "bool found" as global variable .

U must not get the correct error message , correct those all , check your code again , get new version of your code and your errors will be more clear .
Amahdy at 2007-11-11 20:59:34 >
# 2 Re: Why do I have 85 of the exact same error with one module?
I made the corrections you had listed and for some reason, i'm still getting that **** error 85 times. I thought i changed everything you listed....
IBMT43 at 2007-11-11 21:00:41 >
# 3 Re: Why do I have 85 of the exact same error with one module?
Currently I don't have an installed C++ compiler so please post your code here to look throw it again .
Amahdy at 2007-11-11 21:01:40 >
# 4 Re: Why do I have 85 of the exact same error with one module?
here is my attempt to make the changes

#include<iostream>
#include<fstream>
using namespace std;

fstream instream;

struct node; //define the structure of the node
typedef node *node_ptr;

struct node{
int indicator;
char name[20];
int ssnum;
char address[25];
int phone;
node_ptr next;
};

node_ptr list, p, q, prev;

void get_node(node_ptr q);
void print_list(node_ptr list);
void modify(node_ptr list);
void delete_info(node_ptr list);
bool search(node_ptr, node_ptr, );
bool found;

int main(){

int indicator;
node_ptr q;
list = NULL;

//reads the information in from an external file to a linked list
fstream instream;
instream.open("linked2.txt", ios::in);
while (!instream.eof())
{
instream >> indicator;

switch (indicator)
{
case 1: //indicator is 1
search(list, prev, p);
if (!found) // if the value is not in the list already, insert it
{
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
instream >> q->phone;
void get_node(node_ptr q);
}
break;

case 2: //indicator is 2
search(list, prev, p);
if (found) // if the value is already in the list, delete it
{
void delete_info(node_ptr list);
}
break;

case 3: //indicator is 3
search(list, prev, p);
if (found) // if the value is found, modify the phone number
{
void modify(node_ptr p);
}
break;
case 4: //indicator is 4
void print_list(node_ptr list);
break;

default:
break;
}
}
instream.close();

return 0;
}

void get_node(node_ptr q)
{
q = new node;
q->next = NULL;
}

//Indicator = 4 then we print out the info to a formatted table
void print_list(node_ptr list)
{
node_ptr p; //get a temporary pointer and initialize it to the
p = list; //address of the first node

while (p != NULL) //as long as there are more elements in the list
{
cout << "Name \t SS Number \t Address \t Phone Number \t\n";
cout << "___________________________________________________\n";
cout << p->name <<"\t"; //print out the contents of the data field
cout << p->ssnum <<"\t";
cout << p->address <<"\t";
cout << p->phone <<"\t";
p = p->next; //move to the next node
}
}

//Indicator = 3 then the person's telephone number is to be modified
void modify(node_ptr q)
{
q = p;
q->phone = new phone;
}

//Indicator = 2 then the person's information is to be deleted from the linked list
void delete_info(node_ptr q)
{
q = p;
delete q;
q = NULL;
}

//Search routine to determine if information is already in the linked list
bool search(node_ptr list, node_ptr prev, node_ptr p)
{
bool found;
prev = NULL;
p = list;
while ((p!=NULL) && (p->name != name))
{
prev = p;
p = p->next;
if (p == NULL)
found = false; //name not found
else
if (p->name != name)
found = false; //name not found
else
found = true; //name found
}
return (found);
}
IBMT43 at 2007-11-11 21:02:39 >
# 5 Re: Why do I have 85 of the exact same error with one module?
I'm sorry in my previous post I meant the function to be like that :
bool search(node_ptr, node_ptr, node_ptr);
not that :
bool search(node_ptr, node_ptr, );

many other errors :
>q->phone = new phone;
u can't creat new object using a variable name "phone"
correction : new int if u mean that ..

>(p->name != name)
name is a member of the struct node, to correct this u need to specify which node.name to compare with it..

now recheck all your code to find similar errors, I think if u remove them the 85 errors will disapare as I told u before, not all errors explaination are good explained .
Amahdy at 2007-11-11 21:03:39 >
# 6 Re: Why do I have 85 of the exact same error with one module?
I am down to seven errors now

#include<iostream>
#include<fstream>
using namespace std;

fstream instream;

struct node; //define the structure of the node
typedef node *node_ptr;

struct node{
int indicator;
char name[20];
int ssnum;
char address[25];
int phone;
node_ptr next;
};

node_ptr list, p, q, prev;

void get_node(node_ptr q);
void print_list(node_ptr list);
void modify(node_ptr list);
void delete_info(node_ptr list);
bool search(node_ptr, node_ptr, node_ptr);
bool found;

int main(){

int indicator;
node_ptr q;
list = NULL;

//reads the information in from an external file to a linked list
fstream instream;
instream.open("linked2.txt", ios::in);
while (!instream.eof())
{
instream >> indicator;

switch (indicator)
{
case 1: //indicator is 1
search(list, prev, p);
if (!found) // if the value is not in the list already, insert it
{
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
instream >> q->phone;
void get_node(node_ptr q);
}
break;

case 2: //indicator is 2
search(list, prev, p);
if (found) // if the value is already in the list, delete it
{
void delete_info(node_ptr list);
}
break;

case 3: //indicator is 3
search(list, prev, p);
if (found) // if the value is found, modify the phone number
{
void modify(node_ptr p);
}
break;

case 4: //indicator is 4
void print_list(node_ptr list);
break;

default:
break;
}
}
instream.close();

return 0;
}

void get_node(node_ptr q)
{
q = new node;
q->next = NULL;
}

//Indicator = 4 then we print out the info to a formatted table
void print_list(node_ptr list)
{
node_ptr p; //get a temporary pointer and initialize it to the
p = list; //address of the first node

while (p != NULL) //as long as there are more elements in the list
{
cout << "Name \t SS Number \t Address \t Phone Number \t\n";
cout << "___________________________________________________\n";
cout << p->name <<"\t"; //print out the contents of the data field
cout << p->ssnum <<"\t";
cout << p->address <<"\t";
cout << p->phone <<"\t";
p = p->next; //move to the next node
}
}

//Indicator = 3 then the person's telephone number is to be modified
void modify(node_ptr q)
{
q = p;
q->phone = new int;
}

//Indicator = 2 then the person's information is to be deleted from the linked list
void delete_info(node_ptr q)
{
q = p;
delete q;
q = NULL;
}

//Search routine to determine if information is already in the linked list
bool search(node_ptr list, node_ptr prev, node_ptr p)
{
bool found;
prev = NULL;
p = list;
while ((p!=NULL) && (p->name != name))
{
prev = p;
p = p->next;
if (p == NULL)
found = false; //name not found
else
if (p->node.name != node.name)
found = false; //name not found
else
found = true; //name found
}
return (found);
}

-------Configuration: Program_4_Linked_ListDEVEDIT - Win32 Debug-------
Compiling...
Program_4_Linked_ListDEVEDIT.cpp
C:\Documents and Settings\ms219548\My Documents\School\Data\final\Program_4_Linked_ListDEVEDIT.cpp(151) : error C2440: '=' : cannot convert from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\ms219548\My Documents\School\Data\final\Program_4_Linked_ListDEVEDIT.cpp(169) : error C2065: 'name' : undeclared identifier
C:\Documents and Settings\ms219548\My Documents\School\Data\final\Program_4_Linked_ListDEVEDIT.cpp(169) : error C2446: '!=' : no conversion from 'int' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\ms219548\My Documents\School\Data\final\Program_4_Linked_ListDEVEDIT.cpp(169) : error C2040: '!=' : 'char [20]' differs in levels of indirection from 'int'
C:\Documents and Settings\ms219548\My Documents\School\Data\final\Program_4_Linked_ListDEVEDIT.cpp(176) : error C2273: 'function-style cast' : illegal as right side of '->' operator
C:\Documents and Settings\ms219548\My Documents\School\Data\final\Program_4_Linked_ListDEVEDIT.cpp(176) : error C2228: left of '.name' must have class/struct/union type
C:\Documents and Settings\ms219548\My Documents\School\Data\final\Program_4_Linked_ListDEVEDIT.cpp(176) : error C2275: 'node' : illegal use of this type as an expression
C:\Documents and Settings\ms219548\My Documents\School\Data\final\Program_4_Linked_ListDEVEDIT.cpp(46) : see declaration of 'node'
Error executing cl.exe.

Program_4_Linked_ListDEVEDIT.exe - 7 error(s), 0 warning(s)
IBMT43 at 2007-11-11 21:04:49 >
# 7 Re: Why do I have 85 of the exact same error with one module?
gr8 , tomorow (isa) I'll try to see those errors , however I think the new int method is invalid and your nade.name metho too coz you must specify a variabel not the structure itself ..
Amahdy at 2007-11-11 21:05:47 >
# 8 Re: Why do I have 85 of the exact same error with one module?
Okay, so with that last module, i changed it to this

this reduced me down to only 1 ERROR! ONLY ONE!

so here is my one error

C:\Documents and Settings\ms219548\My Documents\Data\Program_4_Linked_ListDEVEDIT.cpp(148) : error C2440: '=' : cannot convert from 'int *' to 'int'

Totally lost on this one!

bool search(node_ptr list, node_ptr prev, node_ptr p)
{
bool found;
prev = NULL;
p = list;
while ((p!=NULL) && (p->name != p->name))
{
prev = p;
p = p->next;
if (p == NULL)
found = false; //name not found
else
if (p->name != p->name)
found = false; //name not found
else
found = true; //name found
}
return (found);
}
IBMT43 at 2007-11-11 21:06:46 >
# 9 Re: Why do I have 85 of the exact same error with one module?
what is the meaning of "if (p->name != p->name)" !!!

reducing the number of error doesn't implies having a logicaly working programme ..

your if condition will be true for ever .. you should have to compare with a diffent member .
About the last error I don't know where is exactly but it seems u try to assigne a pointer to a static integer .
Amahdy at 2007-11-11 21:07:43 >
# 10 Re: Why do I have 85 of the exact same error with one module?
good point.....crap
IBMT43 at 2007-11-11 21:08:45 >
# 11 Re: Why do I have 85 of the exact same error with one module?
As I told u ; the two functions : modify() and search() are not well formed , what u want by making phone as new integer or as new what ..
and in search u pass for example "prev" and then u make it null , and in the loop u assigne the passed p to prev , It seems u have many problems with those two functions u must redefine them to show what u want exactly , If u can't go tell us what u want and we will try to help u .
Amahdy at 2007-11-11 21:09:54 >
# 12 Re: Why do I have 85 of the exact same error with one module?
Here is an update -- I don't think that its linking

i'll list the code and the file

anything would help -- we don't understand why its not working

#include<iostream>
#include<fstream>
using namespace std;

fstream instream;

struct node; //define the structure of the node
typedef node *node_ptr;

struct node{
int indicator;
char name[20];
int ssnum;
char address[25];
int phone;
node_ptr next;
};

node_ptr list, p, q, prev;

void get_node(node_ptr &q);
void print_list(node_ptr list);
void modify(node_ptr q, node_ptr &p);
void delete_info(node_ptr &prev, node_ptr &p, node_ptr &list);
void insert(node_ptr p, node_ptr q, node_ptr prev, node_ptr list);
bool search(node_ptr list, node_ptr prev, node_ptr p, node_ptr q);
bool found;

int main(){

int indicator;
list = NULL;
prev = NULL;
p = NULL;
q = NULL;

//reads the information in from an external file to a linked list
fstream instream;
instream.open("linked2.txt", ios::in);
while (!instream.eof())
{
instream >> indicator;

switch (indicator)
{
case 1: //indicator is 1
cout << "Entering insert \n";

// if the value is not in the list already, insert it
{
get_node(q);
instream >> q->name; cout<<q->name << endl;
instream >> q->ssnum;
instream >> q->address;
instream >> q->phone;
}

bool foundit;
foundit = search(list, prev, p, q);
if (!foundit)
insert( p, q, prev, list);
else
cout << "Already in the list.\n";
cout << "Leaving insert\n\n";
break;

case 2: //indicator is 2
cout << "Deleting from list \n\n";
search(list, prev, p, q);
instream >> q->name;
instream >> q->ssnum;
if (found) // if the value is already in the list, delete it
{
delete_info(prev, p, list);
}
break;

case 3: //indicator is 3
cout << "Modifying phone number \n\n";
search(list, prev, p, q);
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
if (found) // if the value is found, modify the phone number
{
modify(q, p);
}
break;

case 4: //indicator is 4
cout << "Printing the list \n\n";
print_list(list);
break;

default: //indicator is not a 1, 2, 3, or 4
cout << "TU ESTUPIDO! "<<indicator<<" is not a valid indicator number\n";
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
instream >> q->phone;

break;

}
}
instream.close();

return 0;
} // end of main

void get_node(node_ptr &q)
{
q = new node;
q->next = NULL;
}

//Indicator = 1 then we insert the node to the linked list
void insert(node_ptr p, node_ptr q, node_ptr prev, node_ptr list)
{
if (prev != NULL)
{
q->next = prev->next;
prev->next = q;
}
else
{
q->next = list;
list = q;
}
}

//Indicator = 4 then we print out the info to a formatted table
void print_list(node_ptr list)
{
node_ptr p; //get a temporary pointer and initialize it to the
p = list; //address of the first node

while (p != NULL) //as long as there are more elements in the list
{
cout << "Name \t SS Number \t Address \t Phone Number \t\n";
cout << "___________________________________________________\n";
cout << p->name <<"\t"; //print out the contents of the data field
cout << p->ssnum <<"\t";
cout << p->address <<"\t";
cout << p->phone <<"\t";
p = p->next; //move to the next node
}
}

//Indicator = 3 then the person's telephone number is to be modified
void modify(node_ptr q, node_ptr &p)
{
p->phone = q->phone;
}

//Indicator = 2 then the person's information is to be deleted from the linked list
void delete_info(node_ptr &prev, node_ptr &p, node_ptr &list)
{
if (prev == NULL)
{
list = p->next;
delete p;
p = NULL;
}
else
{
prev->next = p->next;
delete p;
p = NULL;
}
}

//Search routine to determine if information is already in the linked list
bool search(node_ptr list, node_ptr prev, node_ptr p, node_ptr q)
{
bool found;
prev = NULL;
p = list;

while ((p!=NULL) && (strcmp(p->name, q->name)!=0) && (strcmp(p->name, q->name)<0))
{
prev = p;
p = p->next;
}
if (p == NULL)
found = false; //name not found
else
if (strcmp(p->name,q->name)==0)
found = false; //name not found
else
found = true; //name fund
return (found);
}

1 Ant,Adam____________ 111111111 1534_Ant_Hill_Rd.________ 4683924
1 Zettel,Dr._Larry____ 222222222 103_Loras_College________ 5887152
1 Litka,Mark__________ 343434343 201_Smith________________ 4343434
1 Aikin,Howard________ 555555555 135_Mark_Street__________ 5342222
1 Litka,Brenda________ 999000999 201_Smith________________ 4343434
1 Aikin,Howard________ 555555555 135_Mark_Street__________ 5342222
3 Aikin,Howard________ 555555555 4000111
4
2 Aikin,Howard________ 555555555
2 Clark,Susan_________ 131313131
2 Litka,Brenda________ 999999999
4
3 Zettel,Dr._Larry____ 222222222 2020202
1 Smith,Cathy_________ 123456789 555_Somewhere_Dr.________ 5880001
1 Smith,Bubba_________ 200000000 1st._Team_Street_________ 5823654
2 Aaron,Susan_________ 444455554
2 Zipzo,Karl__________ 989876765
3 Ant,Adam____________ 111111101 5454545
4
7 Ant,Adam____________ 111111111 1534_Ant_Hill_Rd.________ 4683924
2 Zettel,Dr._Larry____ 222222222
1 Zorro,Monty_________ 979594939 Golden_Days_of_Hollywood_ 6349785
1 Adam,Mary___________ 456297058 6649_Burnly______________ 2657948
3 Litka,Mark__________ 343434343 5897798
1 Smith,Cathy_________ 234567890 1525_St._Charles_________ 9997826
1 Tuoka,Mark__________ 343434343 201_Pleasant_Valley_Road_ 8888888
4
IBMT43 at 2007-11-11 21:10:53 >
# 13 Re: Why do I have 85 of the exact same error with one module?
First try to change any line number by any other number "say 5" and see results ..

Now you have a problem with the print_list() function, it will never print coz the calling is not recognized , what does "list" represent for it in case 4; check this again .
Amahdy at 2007-11-11 21:11:54 >
# 14 Re: Why do I have 85 of the exact same error with one module?
We've gotten a bit further and it prints out stuff now, but not for what we want it to do -- also i think there are something wrong with our delete module

i did insert 5 in the file, for the line right after the first 4, and the program went nuts, but if i put the 5 anywhere else it works

#include<iostream>
#include<fstream>
using namespace std;

fstream instream;

struct node; //define the structure of the node
typedef node *node_ptr;

struct node{
int indicator;
char name[20];
int ssnum;
char address[25];
int phone;
node_ptr next;
};

node_ptr list, p, q, prev;

void get_node(node_ptr &q);
void print_list(node_ptr list);
void modify(node_ptr q, node_ptr &p);
void delete_info(node_ptr prev, node_ptr p, node_ptr &list);
void insert(node_ptr prev, node_ptr q, node_ptr &list, node_ptr p);
bool search(node_ptr list, node_ptr prev, node_ptr p, node_ptr q);
bool found;

int main(){

int indicator;
list = NULL;
prev = NULL;
p = NULL;
q = NULL;

//reads the information in from an external file to a linked list
fstream instream;
instream.open("linked2.txt", ios::in);

while (!instream.eof())
{
instream >> indicator;

switch (indicator)
{
case 1: //indicator is 1
cout << "Entering insert \n";

// if the value is not in the list already, insert it
{
get_node(q);
instream >> q->name; cout<<q->name << endl;
instream >> q->ssnum;
instream >> q->address;
instream >> q->phone;
}

bool foundit;
foundit = search(list, prev, p, q);
if (!foundit)
insert( prev, q, list, p);
else
cout << "Already in the list.\n";
cout << "Leaving insert\n\n";
break;

case 2: //indicator is 2
cout << "Deleting from list \n\n";
instream >> q->name;
instream >> q->ssnum;
bool found_name;
found_name = search(list, prev, p, q);
if (found_name) // if the value is already in the list, delete it
{
delete_info(prev, p, list);
}
break;

case 3: //indicator is 3
cout << "Modifying phone number \n\n";
search(list, prev, p, q);
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
if (found) // if the value is found, modify the phone number
{
modify(q, p);
}
break;

case 4: //indicator is 4
cout << "Printing the list \n\n";
if (list == NULL)
cout << "There is nothing in the list\n";
print_list(list);
break;

default: //indicator is not a 1, 2, 3, or 4
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
instream >> q->phone;
cout << "ERROR! "<<indicator<<" is not a valid indicator number\n\n";
break;
}
}
instream.close();

return 0;
} // end of main

void get_node(node_ptr &q)
{
q = new node;
q->next = NULL;
}

//Indicator = 1 then we insert the node to the linked list
void insert(node_ptr prev, node_ptr q, node_ptr &list, node_ptr p)
{
if (prev != NULL)
{
q->next = prev->next;
prev->next = q;
}

else
{
q->next = list;
list = q;
}
}

//Indicator = 4 then we print out the info to a formatted table
void print_list(node_ptr list)
{
node_ptr p; //get a temporary pointer and initialize it to the
p = list; //address of the first node

while (p != NULL) //as long as there are more elements in the list
{
cout << "Name \t SS Number \t Address \t Phone Number \t\n";
cout << "_______________________________________________________________\n";
cout << p->name <<"\t"; //print out the contents of the data field
cout << p->ssnum <<"\t";
cout << p->address <<"\t";
cout << p->phone <<"\t";
p = p->next; //move to the next node
}
}

//Indicator = 3 then the person's telephone number is to be modified
void modify(node_ptr q, node_ptr &p)
{
p->phone = q->phone;
}

//Indicator = 2 then the person's information is to be deleted from the linked list
void delete_info(node_ptr prev, node_ptr p, node_ptr &list)
{
if (prev == NULL)
{
list = p->next;
delete p;
p = NULL;
}

else
{
prev->next = p->next;
delete p;
p = NULL;
}
}

//Search routine to determine if information is already in the linked list
bool search(node_ptr list, node_ptr prev, node_ptr p, node_ptr q)
{
bool found;
prev = NULL;
p = list;

while ((p!=NULL) && (strcmp(p->name, q->name)!=0) && (strcmp(p->name, q->name)<0))
{
prev = p;
p = p->next;
}
if (p == NULL)
found = false; //name not found
else
if (strcmp(p->name,q->name)==0)
found = false; //name not found
else
found = true; //name found
return (found);
}
IBMT43 at 2007-11-11 21:12:50 >
# 15 Re: Why do I have 85 of the exact same error with one module?
I'm sorry for all the updates -- but we have gotten FAR!

Okay, so the prob we are having now, is that our info comes in fine, we are able to print the info before we do things with it, but once we send it through the process and print it out, it goes adds numbers and characters

Here is the Code

My output will be on a different post because this **** forum won't let me put it all on there

#include<iostream>
#include<fstream>
using namespace std;

fstream instream;

struct node; //define the structure of the node
typedef node *node_ptr;

struct node{
char name[20];
long int ssnum;
char address[25];
long int phone;
node_ptr next;
};

node_ptr list, p, q, prev;

void get_node(node_ptr &q);
void print_list(node_ptr list);
void modify(node_ptr q, node_ptr &p);
void delete_info(node_ptr prev, node_ptr p, node_ptr &list);
void insert(node_ptr prev, node_ptr q, node_ptr &list, node_ptr p);
bool search(node_ptr list, node_ptr &prev, node_ptr &p, node_ptr q);
bool found;

int main(){

int indicator;
list = NULL;
prev = NULL;
p = NULL;
q = NULL;

//reads the information in from an external file to a linked list
fstream instream;
instream.open("trial.txt", ios::in);

while (!instream.eof())
{
instream >> indicator;

switch (indicator)
{
case 1: //indicator is 1
cout << "Entering insert \n";

// if the value is not in the list already, insert it
{
get_node(q);
instream >> q->name; cout<<"*******************" <<q->name << endl;
instream >> q->ssnum; cout<<"*******************" <<q->ssnum << endl;
instream >> q->address; cout<<"*******************" <<q->address << endl;
instream >> q->phone; cout<<"*******************" <<q->phone << endl;
}

bool foundit;
foundit = search(list, prev, p, q);
if (foundit == false)
insert( prev, q, list, p);
else
cout << "Already in the list.\n";
cout << "Leaving insert\n\n";
break;

case 2: //indicator is 2
cout << "Deleting from list \n\n";
get_node(q);
instream >> q->name;
instream >> q->ssnum;
bool found_name;
found_name = search(list, prev, p, q);
if (found_name) // if the value is already in the list, delete it
{
delete_info(prev, p, list);
}
break;

case 3: //indicator is 3
cout << "Modifying phone number \n\n";
get_node(q);
bool searchname;
searchname = search(list, prev, p, q);
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
if (found) // if the value is found, modify the phone number
{
modify(q,p);
}
break;

case 4: //indicator is 4
cout << "Printing the list \n\n";
if (list == NULL)
cout << "There is nothing in the list\n";
print_list(list);
break;

default: //indicator is not a 1, 2, 3, or 4
instream >> q->name;
instream >> q->ssnum;
instream >> q->address;
instream >> q->phone;
cout << "ERROR! "<<indicator<<" is not a valid indicator number\n\n";
break;
}
}
instream.close();

return 0;
} // end of main

void get_node(node_ptr &q)
{
q = new node;
q->next = NULL;
}

//Indicator = 1 then we insert the node to the linked list
void insert(node_ptr prev, node_ptr q, node_ptr &list, node_ptr p)
{
if (prev != NULL)
{
q->next = prev->next;
prev->next = q;
}

else
{
q->next = list;
list = q;
}
}

//Indicator = 4 then we print out the info to a formatted table
void print_list(node_ptr list)
{
node_ptr p; //get a temporary pointer and initialize it to the
p = list; //address of the first node
cout << "Name \t\t SS Number \t\t Address \t\t Phone Number \t\t\n";
while (p != NULL) //as long as there are more elements in the list
{
cout << p->name ; //print out the contents of the data field
cout << p->ssnum ;
cout << p->address ;
cout << p->phone ;
p = p->next; //move to the next node
cout<<endl;
}
}

//Indicator = 3 then the person's telephone number is to be modified
void modify(node_ptr q, node_ptr &p)
{
p->phone = q->phone;
}

//Indicator = 2 then the person's information is to be deleted from the linked list
void delete_info(node_ptr prev, node_ptr p, node_ptr &list)
{
if (prev == NULL)
{
list = p->next;
delete p;
p = NULL;
}

else
{
prev->next = p->next;
delete p;
p = NULL;
}
}

//Search routine to determine if information is already in the linked list
bool search(node_ptr list, node_ptr &prev, node_ptr &p, node_ptr q)
{
bool found;
prev = NULL;
p = list;

while ((p!=NULL) && (strcmp(p->name, q->name)!=0) && (strcmp(p->name, q->name)<0))
{
prev = p;
p = p->next;
}
if (p == NULL)
found = false; //name not found
else
if (strcmp(p->name,q->name)==0)
found = true; //name not found
else
found = false; //name found
return (found);
}
IBMT43 at 2007-11-11 21:13:54 >
# 16 Re: Why do I have 85 of the exact same error with one module?
OUTPUT

Entering insert
*****Ant,Adam____________
*****111111111
*****1534_Ant_Hill_Rd.________
*****4683924
Leaving insert

Entering insert
*****Zettel,Dr._Larry____
*****222222222
*****103_Loras_College________
*****5887152
Leaving insert

Entering insert
*****Litka,Mark__________
*****343434343
*****201_Smith________________
*****4343434
Leaving insert

Entering insert
*****Aikin,Howard________
*****555555555
*****135_Mark_Street__________
*****5342222
Leaving insert

Entering insert
*****Litka,Brenda________
*****999000999
*****201_Smith________________
*****4343434
Leaving insert

Entering insert
*****Aikin,Howard________
*****555555555
*****135_Mark_Street__________
*****5342222
Already in the list.
Leaving insert

Modifying phone number

Printing the list

Name SS Number Address Phone Number
_______________________________________________________________
Aikin,Howard________π→↔!135_Mark_Street__________ 555555555 135_Mark_Street__________ 5342222 Name SS Number
Address Phone Number
_______________________________________________________________
Ant,Adam____________╟k♠1534_Ant_Hill_Rd.________ 111111111 1534_Ant_Hill_Rd.________ 4683924 Name SS Number
Address Phone Number
_______________________________________________________________
Litka,Brenda________;201_Smith________________ 999000999 201_Smith________________ 4343434 Name SS Number
Address Phone Number
_______________________________________________________________
Litka,Mark__________gdx201_Smith________________ 343434343 201_Smith________________ 4343434 Name SS Number
Address Phone Number
_______________________________________________________________
103_Loras_College________ 222222222 103_Loras_College________ 5887152
Deleting from list

Deleting from list

Deleting from list

Printing the list

Name SS Number Address Phone Number
_______________________________________________________________
Aikin,Howard________π→↔!135_Mark_Street__________ 555555555 135_Mark_Street__________ 5342222 Name SS Number
Address Phone Number
_______________________________________________________________
Ant,Adam____________╟k♠1534_Ant_Hill_Rd.________ 111111111 1534_Ant_Hill_Rd.________ 4683924 Name SS Number
Address Phone Number
_______________________________________________________________
Litka,Brenda________;201_Smith________________ 999000999 201_Smith________________ 4343434 Name SS Number
Address Phone Number
_______________________________________________________________
Litka,Mark__________gdx201_Smith________________ 343434343 201_Smith________________ 4343434 Name SS Number
Address Phone Number
_______________________________________________________________
103_Loras_College________ 222222222 103_Loras_College________ 5887152
Modifying phone number

Entering insert
*****Smith,Cathy_________
*****123456789
*****555_Somewhere_Dr.________
*****5880001
Leaving insert

ERROR! 5 is not a valid indicator number

Deleting from list

Deleting from list

Modifying phone number

Printing the list

Name SS Number Address Phone Number
_______________________________________________________________
Aikin,Howard________π→↔!135_Mark_Street__________ 555555555 135_Mark_Street__________ 5342222 Name SS Number
Address Phone Number
_______________________________________________________________
Ant,Adam____________╟k♠1534_Ant_Hill_Rd.________ 111111111 1534_Ant_Hill_Rd.________ 4683924 Name SS Number
Address Phone Number
_______________________________________________________________
Litka,Brenda________;201_Smith________________ 999000999 201_Smith________________ 4343434 Name SS Number
Address Phone Number
_______________________________________________________________
Litka,Mark__________gdx201_Smith________________ 343434343 201_Smith________________ 4343434 Name SS Number
Address Phone Number
_______________________________________________________________
103_Loras_College________ 222222222 103_Loras_College________ 5887152
ERROR! 7 is not a valid indicator number

Deleting from list

Entering insert
*****Zorro,Monty_________
*****979594939
*****Golden_Days_of_Hollywood_
*****6349785
Leaving insert

Entering insert
*****Adam,Mary___________
*****456297058
*****6649_Burnly______________
*****2657948
Leaving insert

Modifying phone number

Entering insert
*****Smith,Cathy_________
*****234567890
*****1525_St._Charles_________
*****9997826
Leaving insert

Entering insert
*****Tuoka,Mark__________
*****343434343
*****201_Pleasant_Valley_Road_
*****8888888
Leaving insert

Printing the list

Name SS Number Address Phone Number
_______________________________________________________________
Litka,Mark__________gdx5897798 343434343 5897798 2657948 Name SS Number Address Phone Number
_______________________________________________________________
Aikin,Howard________π→↔!135_Mark_Street__________ 555555555 135_Mark_Street__________ 5342222 Name SS Number
Address Phone Number
_______________________________________________________________
Ant,Adam____________╟k♠1534_Ant_Hill_Rd.________ 111111111 1534_Ant_Hill_Rd.________ 4683924 Name SS Number
Address Phone Number
_______________________________________________________________
Litka,Brenda________;201_Smith________________ 999000999 201_Smith________________ 4343434 Name SS Number
Address Phone Number
_______________________________________________________________
Litka,Mark__________gdx201_Smith________________ 343434343 201_Smith________________ 4343434 Name SS Number
Address Phone Number
_______________________________________________________________
1525_St._Charles_________ 234567890 1525_St._Charles_________ 9997826 Name SS Number Address Phone
Number
_______________________________________________________________
Tuoka,Mark__________gdx201_Pleasant_Valley_Road_ 343434343 201_Pleasant_Valley_Road_ 8888888 Name SS Number
Address Phone Number
_______________________________________________________________
103_Loras_College________ 222222222 103_Loras_College________ 5887152 Name SS Number Address Phone
Number
_______________________________________________________________
Zorro,Monty_________╗nc:Golden_Days_of_Hollywood_ 979594939 Golden_Days_of_Hollywood_ 6349785
Press any key to continue
IBMT43 at 2007-11-11 21:14:52 >
# 17 Re: Why do I have 85 of the exact same error with one module?
Strings in C++ expect to end with a zero -- it looks like you are forcing it to write out data (garbage) beyond the end of the string.
jonnin at 2007-11-11 21:15:56 >
# 18 Re: Why do I have 85 of the exact same error with one module?
You must not print all the array ; for example name[20] contains 20 character, if the name is only 15 character and you print out the whole array the rest 5 character will be like u see in the output (any characters) .. You may use pointers, or specify the number of characters to print on each name , adress and all that .
Amahdy at 2007-11-11 21:16:55 >