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


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

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

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

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

  2. #17
    Join Date
    Dec 2006
    Posts
    10
    OUTPUT

    Code:
    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

  3. #18
    Join Date
    Dec 2003
    Posts
    3,366
    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.

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

Similar Threads

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