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


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 19

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

Hybrid View

  1. #1
    Join Date
    Dec 2006
    Posts
    10

    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,

    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);
    }

  2. #2
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    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 .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  3. #3
    Join Date
    Dec 2006
    Posts
    10
    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.....

  4. #4
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    Currently I don't have an installed C++ compiler so please post your code here to look throw it again .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  5. #5
    Join Date
    Dec 2006
    Posts
    10
    here is my attempt to make the changes

    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(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);
    }

  6. #6
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    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 .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  7. #7
    Join Date
    Dec 2006
    Posts
    10
    I am down to seven errors now

    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(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);
    }
    Code:
    --------------------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)

  8. #8
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819

    Arrow

    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 ..
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  9. #9
    Join Date
    Dec 2006
    Posts
    10
    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!
    Code:
    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);
    }

  10. #10
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    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 .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  11. #11
    Join Date
    Dec 2006
    Posts
    10
    good point......crap

  12. #12
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    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 .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  13. #13
    Join Date
    Dec 2006
    Posts
    10
    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

    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 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);
    }
    Code:
    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

  14. #14
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    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 .
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  15. #15
    Join Date
    Dec 2006
    Posts
    10
    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
    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 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);
    }
    Last edited by IBMT43; 12-12-2006 at 06:03 PM.

Similar Threads

  1. adding a module to a project
    By harish13 in forum VB Classic
    Replies: 1
    Last Post: 07-27-2006, 03:44 AM
  2. How to use timer in a module
    By shuiqq in forum VB Classic
    Replies: 3
    Last Post: 11-28-2005, 03:02 PM
  3. Replies: 0
    Last Post: 11-14-2002, 10:50 PM
  4. HTML Control & Code Behind Module!
    By hari in forum ASP.NET
    Replies: 2
    Last Post: 04-02-2002, 04:21 PM
  5. Index server module??
    By Duncan Atack in forum Web
    Replies: 0
    Last Post: 07-13-2000, 11:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center