12 Replies - 1506 Views - Last Post: 28 September 2014 - 11:47 AM Rate Topic: -----

#1 Fizza_94   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-September 14

unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 02:00 AM

i was given a task to convert infix to post fix using both linked lists and stacks in the code so this is what i have written but the problem is it is giving me same error at three different places "missing function header(old style format?) , can anyone please tell me what is wrong with my code?

#include <iostream>
#include <string>

using namespace std;
const int size = 100;

class stack{
private: // Declare a structure for the list
struct ListNode
{
char value;
struct ListNode *next;
struct ListNode *back;
};
int top;
char data[size];
ListNode *head; // List head pointer
ListNode *tail;// tail pointer
public:
stack(void) // Constructor
{
head = NULL;
tail = NULL;
}

	
public: // function declaration
	void appendNode(char num);
	void forward(void);
	void deleteNode(char num);
	void input(void);
	void convert(void);
	void createStack();
	void push(char); // insert operation
	char pop(); // delete operation
	char stackTop(); // get top value
	bool isFull(); // check if stack is Full
	bool isEmpty(); // check if stack is empty
	bool prcd(char symb);
};

void stack::createStack(){
	
	
		top = -1;
	
}
bool stack::isFull()
{
	return (top == size - 1);
}
bool stack::isEmpty()
{
	return (top == -1);
}
void stack::push(char newitem)
{
	if (isFull()){
		cout << "sorry cannot push stack is full \n";

	}
	else {
		top = top + 1;
		data[top] = newitem;
	}
}//end push()
char stack::pop()
{
	char item;
	if (isEmpty()){
		cout << "Sorry, Cannot pop item.Stack is empty!" << endl;
	}
	else
	{ //display value at top to be deleted
		cout << "Popped value : " << data[top];
		top -=1;
		return data[top];

		// top will hold to new index
	}// end else
}//end pop

char stack::stackTop()
{ //function to get top value
	stack obj2;
	if (obj2.isEmpty()){
	cout << "Sorry, stack is empty!" << endl;
}
	else
		return data[top];
} // end stackTop
bool stack:: prcd(char symb)//checks the precedence of the operators
{
	if ((data[top] == '+') && (symb == '*'))
		return false;
	else if ((data[top] == '-') && (symb == '*'))
		return false;
	else if ((data[top] == '+') && (symb == '/'))
		return false;
	else if ((data[top] == '-') && (symb == '/'))
		return false;

	else if ((data[top] == ('+' || '-' || '*' || '/')) && (symb == '('))
		return false;
	else if (data[top] == '(' && symb == ('+' || '-' || '*' || '/'))
		return false;
	else if (data[top] == '(' && symb == ')')
		return false;
	else if ((data[top] != ')') && (symb == '('))
		return false;
	else
		return true;
}

	void stack::appendNode(char num)
	{
		ListNode *newNode, *nodePtr;

		// Allocate a new node & store num
		newNode = new ListNode;
		newNode->value = num;
		newNode->next = NULL;
		// If there are no nodes in the list
		// make newNode the first node
		if (!head)   // head == NULL
			head = newNode;
		else// Otherwise, insert newNode at end
		{
			// Initialize nodePtr to head of list
			nodePtr = head;
			// Find the last node in the list
			while (nodePtr->next)
				nodePtr = nodePtr->next;
			// Insert newNode as the last node
			nodePtr->next = newNode;
		}

	}
	void stack::forward(void)
	{
		ListNode *nodePtr;

		nodePtr = head;
		while (nodePtr)
		{
			cout << nodePtr->value<< "  ";
			nodePtr = nodePtr->next;
		}

	}

	void stack::deleteNode(char num)
	{
		ListNode *nodePtr, *previousNode=NULL;

		// If the list is empty, do nothing.
		if (!head)
			return;

		// Determine if the first node is the one.
		if (head->value == num)
		{
			nodePtr = head->next;
			delete head;
			head = nodePtr;
		}
		else
		{
			// Initialize nodePtr to head of list
			nodePtr = head;

			// Skip all nodes whose value member is not equal to num.
			while (nodePtr != NULL && nodePtr->value != num)
			{
				previousNode = nodePtr;
				nodePtr = nodePtr->next;
			}

			// Link the previous node to the node after nodePtr, then delete nodePtr.
			previousNode->next = nodePtr->next;
			delete nodePtr;
		}
	}
	

	void stack::convert(){
		ListNode *nodeptr;
		stack s;
		char c;
		string pf='\0';
		char op;
		nodeptr = head;
		s.createStack();
		while (nodeptr){
			c = nodeptr->value;
			if (c == ('+' || '-' || '*' || '/' || '(' || ')')){
				while (!s.isEmpty() && prcd(c)){
					op = s.pop();
					pf += op;
				}
				if (s.isEmpty() || c != ')' ) 
					s.push(c);
				elses.pop(); // discard the ‘(‘ 

			}
			else{
				pf += c;
			}
			nodeptr = nodeptr->next;

		}
		while (!s.isEmpty()) {
			op = s.pop();
			pf += op;
		}

		cout << pf;


	}
	void stack:: input ()
	{
		stack obj;
		char inp;
		cout << "enter the required expresson\n press a to stop\n ";

		cin >> inp;
		obj.appendNode(inp);
		while (inp != 'a'){
			cin >> inp;
			obj.appendNode(inp);
			if (inp == 'a'){
				obj.deleteNode(inp);
			}


	}
		obj.forward();




	}
	void main(){
		stack obj1;
		obj1.input();
	}



Is This A Good Question/Topic? 0
  • +

Replies To: unknown problem, no error but program stop working after 1st call

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2770
  • View blog
  • Posts: 4,429
  • Joined: 21-June 11

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 02:21 AM

View PostFizza_94, on 28 September 2014 - 11:00 AM, said:

it is giving me same error at three different places


Which three places?
Was This Post Helpful? 0
  • +
  • -

#3 Fizza_94   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-September 14

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 02:23 AM

View Postsepp2k, on 28 September 2014 - 02:21 AM, said:

View PostFizza_94, on 28 September 2014 - 11:00 AM, said:

it is giving me same error at three different places


Which three places?


push()66
pop() 80
and
stackTop() 88
Was This Post Helpful? 0
  • +
  • -

#4 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2555
  • View blog
  • Posts: 4,739
  • Joined: 30-May 10

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 02:24 AM

Apart from void main (which should be int main), I only get warnings about reaching the end of non-void functions and unused variables.
$ g++  -Wall bar.cpp
bar.cpp: In member function ‘char stack::pop()’:
bar.cpp:69:8: warning: unused variable ‘item’ [-Wunused-variable]
bar.cpp: In member function ‘char stack::stackTop()’:
bar.cpp:88:1: warning: control reaches end of non-void function [-Wreturn-type]
bar.cpp: In member function ‘char stack::pop()’:
bar.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]



So you need to point to specific lines of code, and not just say "there are errors".


You can make life easier for yourself (and anyone who has to read your code) by adopting a consistent approach to indentation.
Most IDEs will either do this for you automatically, or have an option called "reformat code".

#include <iostream>
#include <string>

using namespace std;
const int size = 100;

class stack {
private:                       // Declare a structure for the list
  struct ListNode {
    char value;
    struct ListNode *next;
    struct ListNode *back;
  };
  int top;
  char data[size];
  ListNode *head;               // List head pointer
  ListNode *tail;               // tail pointer
public:
   stack(void)                  // Constructor
  {
    head = NULL;
    tail = NULL;
} public:                      // function declaration
  void appendNode(char num);
  void forward(void);
  void deleteNode(char num);
  void input(void);
  void convert(void);
  void createStack();
  void push(char);              // insert operation
  char pop();                   // delete operation
  char stackTop();              // get top value
  bool isFull();                // check if stack is Full
  bool isEmpty();               // check if stack is empty
  bool prcd(char symb);
};

void stack::createStack()
{
  top = -1;
}

bool stack::isFull()
{
  return (top == size - 1);
}

bool stack::isEmpty()
{
  return (top == -1);
}

void stack::push(char newitem)
{
  if (isFull()) {
    cout << "sorry cannot push stack is full \n";
  } else {
    top = top + 1;
    data[top] = newitem;
  }
}                               //end push()

char stack::pop()
{
  char item;
  if (isEmpty()) {
    cout << "Sorry, Cannot pop item.Stack is empty!" << endl;
  } else {                      //display value at top to be deleted
    cout << "Popped value : " << data[top];
    top -= 1;
    return data[top];
    // top will hold to new index
  }                             // end else
}                               //end pop

char stack::stackTop()
{                               //function to get top value
  stack obj2;
  if (obj2.isEmpty()) {
    cout << "Sorry, stack is empty!" << endl;
  } else
    return data[top];
}                               // end stackTop

bool stack::prcd(char symb)     //checks the precedence of the operators
{
  if ((data[top] == '+') && (symb == '*'))
    return false;
  else if ((data[top] == '-') && (symb == '*'))
    return false;
  else if ((data[top] == '+') && (symb == '/'))
    return false;
  else if ((data[top] == '-') && (symb == '/'))
    return false;

  else if ((data[top] == ('+' || '-' || '*' || '/')) && (symb == '('))
    return false;
  else if (data[top] == '(' && symb == ('+' || '-' || '*' || '/'))
    return false;
  else if (data[top] == '(' && symb == ')')
    return false;
  else if ((data[top] != ')') && (symb == '('))
    return false;
  else
    return true;
}

void stack::appendNode(char num)
{
  ListNode *newNode, *nodePtr;

  // Allocate a new node & store num
  newNode = new ListNode;
  newNode->value = num;
  newNode->next = NULL;
  // If there are no nodes in the list
  // make newNode the first node
  if (!head)                    // head == NULL
    head = newNode;
  else                          // Otherwise, insert newNode at end
  {
    // Initialize nodePtr to head of list
    nodePtr = head;
    // Find the last node in the list
    while (nodePtr->next)
      nodePtr = nodePtr->next;
    // Insert newNode as the last node
    nodePtr->next = newNode;
  }
}

void stack::forward(void)
{
  ListNode *nodePtr;

  nodePtr = head;
  while (nodePtr) {
    cout << nodePtr->value << "  ";
    nodePtr = nodePtr->next;
  }
}

void stack::deleteNode(char num)
{
  ListNode *nodePtr, *previousNode = NULL;

  // If the list is empty, do nothing.
  if (!head)
    return;

  // Determine if the first node is the one.
  if (head->value == num) {
    nodePtr = head->next;
    delete head;
    head = nodePtr;
  } else {
    // Initialize nodePtr to head of list
    nodePtr = head;

    // Skip all nodes whose value member is not equal to num.
    while (nodePtr != NULL && nodePtr->value != num) {
      previousNode = nodePtr;
      nodePtr = nodePtr->next;
    }

    // Link the previous node to the node after nodePtr, then delete nodePtr.
    previousNode->next = nodePtr->next;
    delete nodePtr;
  }
}


void stack::convert()
{
  ListNode *nodeptr;
  stack s;
  char c;
  string pf = '\0';
  char op;
  nodeptr = head;
  s.createStack();
  while (nodeptr) {
    c = nodeptr->value;
    if (c == ('+' || '-' || '*' || '/' || '(' || ')')) {
      while (!s.isEmpty() && prcd(c)) {
        op = s.pop();
        pf += op;
      }
      if (s.isEmpty() || c != ')')
        s.push(c);
      else
        s.pop();               // discard the ‘(‘
    } else {
      pf += c;
    }
    nodeptr = nodeptr->next;
  }
  
  while (!s.isEmpty()) {
    op = s.pop();
    pf += op;
  }

  cout << pf;
}

void stack::input()
{
  stack obj;
  char inp;
  cout << "enter the required expresson\n press a to stop\n ";

  cin >> inp;
  obj.appendNode(inp);
  while (inp != 'a') {
    cin >> inp;
    obj.appendNode(inp);
    if (inp == 'a') {
      obj.deleteNode(inp);
    }
  }
  obj.forward();
}

int main()
{
  stack obj1;
  obj1.input();
}


This post has been edited by Salem_c: 28 September 2014 - 02:27 AM

Was This Post Helpful? 0
  • +
  • -

#5 Fizza_94   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-September 14

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 08:21 AM

ohhh... thank you and sorry, it was a stupid mistake...
Was This Post Helpful? 0
  • +
  • -

#6 Fizza_94   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-September 14

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 08:41 AM

so this is my program to convert INFIX to PREFIX ,
i had a few errors at first but they are now gone and the program is running but after posting the input , program suddenly stopped, now it is not giving an error , and i cant find anything wrong with it can some one please tell me what have i done wrong..
thank you.
#include <iostream>
#include <string>

using namespace std;
const int size = 100;

class stack {
private:                       // Declare a structure for the list
	struct ListNode {
		char value;
		struct ListNode *next;
		struct ListNode *back;
	};
	int top;
	char data[size];
	ListNode *head;               // List head pointer
	ListNode *tail;               // tail pointer
public:
	stack(void)                  // Constructor
	{
		head = NULL;
		tail = NULL;
	} public:                      // function declaration
		void appendNode(char num);
		void forward(void);
		void deleteNode(char num);
		void input(void);
		void convert(void);
		void createStack();
		void push(char);              // insert operation
		char pop();                   // delete operation
		char stackTop();              // get top value
		bool isFull();                // check if stack is Full
		bool isEmpty();               // check if stack is empty
		bool prcd(char symb);
		bool isOperator(char num);
};

void stack::createStack()
{
	top = -1;
}

bool stack::isFull()
{
	return (top == size - 1);
}

bool stack::isEmpty()
{
	return (top == -1);
}

void stack::push(char newitem)
{
	if (isFull()) {
		cout << "sorry cannot push stack is full \n";
	}
	else {
		top = top + 1;
		data[top] = newitem;
	}
}                               //end push()

char stack::pop()
{
	char item;
	if (isEmpty()) {
		cout << "Sorry, Cannot pop item.Stack is empty!" << endl;
	}
	else {                      //display value at top to be deleted
		cout << "Popped value : " << data[top];
		top -= 1;
		return data[top];
		// top will hold to new index
	}                             // end else
}                               //end pop

char stack::stackTop()
{                               //function to get top value
	stack obj2;
	if (obj2.isEmpty()) {
		cout << "Sorry, stack is empty!" << endl;
	}
	else
		return data[top];
}                               // end stackTop

bool stack::prcd(char symb)     //checks the precedence of the operators
{
	if ((data[top] == '+') && (symb == '*'))
		return false;
	else if ((data[top] == '-') && (symb == '*'))
		return false;
	else if ((data[top] == '+') && (symb == '/'))
		return false;
	else if ((data[top] == '-') && (symb == '/'))
		return false;

	else if ((data[top] == ('+' || '-' || '*' || '/')) && (symb == '('))
		return false;
	else if (data[top] == '(' && symb == ('+' || '-' || '*' || '/'))
		return false;
	else if (data[top] == '(' && symb == ')')
		return false;
	else if ((data[top] != ')') && (symb == '('))
		return false;
	else
		return true;
}

void stack::appendNode(char num)
{
	ListNode *newNode, *nodePtr;

	// Allocate a new node & store num
	newNode = new ListNode;
	newNode->value = num;
	newNode->next = NULL;
	// If there are no nodes in the list
	// make newNode the first node
	if (!head)                    // head == NULL
		head = newNode;
	else                          // Otherwise, insert newNode at end
	{
		// Initialize nodePtr to head of list
		nodePtr = head;
		// Find the last node in the list
		while (nodePtr->next)
			nodePtr = nodePtr->next;
		// Insert newNode as the last node
		nodePtr->next = newNode;
	}
}

void stack::forward(void)
{
	ListNode *nodePtr;

	nodePtr = head;
	while (nodePtr) {
		cout << nodePtr->value << "  ";
		nodePtr = nodePtr->next;
	}
}

void stack::deleteNode(char num)
{
	ListNode *nodePtr, *previousNode = NULL;

	// If the list is empty, do nothing.
	if (!head)
		return;

	// Determine if the first node is the one.
	if (head->value == num) {
		nodePtr = head->next;
		delete head;
		head = nodePtr;
	}
	else {
		// Initialize nodePtr to head of list
		nodePtr = head;

		// Skip all nodes whose value member is not equal to num.
		while (nodePtr != NULL && nodePtr->value != num) {
			previousNode = nodePtr;
			nodePtr = nodePtr->next;
		}

		// Link the previous node to the node after nodePtr, then delete nodePtr.
		previousNode->next = nodePtr->next;
		delete nodePtr;
	}
}
bool stack::isOperator(char num){
	if (num = '+')
		return true;
	else if (num = '-')
		return true;
	else if (num = '*')
		return true;
	else if (num = '/')
		return true;
	else if (num = '(')
		return true;
	else if (num = ')')
		return true;
	else
		return false;

}

void stack::convert()
{
	ListNode *nodeptr;
	stack s;
	char c;
	string pf = '\0';
	char op;
	nodeptr = head;
	s.createStack();
	while (nodeptr) {
		c = nodeptr->value;
		if (isOperator(c)) {
			while (!s.isEmpty() && prcd(c)) {
				op = s.pop();
				pf += op;
			}
			if (s.isEmpty() || c != ')')
				s.push(c);
			else
				s.pop();               // discard the ‘(‘
		}
		else {
			pf += c;
		}
		nodeptr = nodeptr->next;
	}

	while (!s.isEmpty()) {
		op = s.pop();
		pf += op;
	}

	cout << pf;
}

void stack::input()
{
	
	char inp;
	cout << "enter the required expresson\n press a to stop\n ";

	cin >> inp;
	appendNode(inp);
	while (inp != 'a') {
		cin >> inp;
		appendNode(inp);
		if (inp == 'a') {
			deleteNode(inp);
		}
	}
	forward();
	convert();

}

int main()
{
	stack obj;
	obj.input();

}



Was This Post Helpful? 0
  • +
  • -

#7 vividexstance   User is offline

  • Tiocfaidh ár lá
  • member icon

Reputation: 794
  • View blog
  • Posts: 2,880
  • Joined: 31-December 10

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 09:37 AM

You need to increase your compiler's warning/error level because when I compile your code with all warnings/errors enabled, I get this:

Quote

$ g++ -Wall stack.cpp -o stack
stack.cpp: In member function ‘char stack::pop()’:
stack.cpp:67:7: warning: unused variable ‘item’ [-Wunused-variable]
char item;
^
stack.cpp: In member function ‘bool stack::isOperator(char)’:
stack.cpp:177:15: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if (num = '+')
^
stack.cpp:179:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
else if (num = '-')
^
stack.cpp:181:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
else if (num = '*')
^
stack.cpp:183:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
else if (num = '/')
^
stack.cpp:185:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
else if (num = '(')
^
stack.cpp:187:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
else if (num = ')')
^
stack.cpp: In member function ‘char stack::pop()’:
stack.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
} //end pop
^
stack.cpp: In member function ‘char stack::stackTop()’:
stack.cpp:87:1: warning: control reaches end of non-void function [-Wreturn-type]
} // end stackTop
^


Remember that there is a difference between a single assignment operator and two. Just one means its an assignment, two means its a comparison.

*EDIT*:
Please don't make duplicate topics for the same program.

This post has been edited by vividexstance: 28 September 2014 - 09:44 AM
Reason for edit:: Merged topics

Was This Post Helpful? 0
  • +
  • -

#8 Fizza_94   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-September 14

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 09:46 AM

still no change after replacing '=' with '=='.
Was This Post Helpful? 0
  • +
  • -

#9 vividexstance   User is offline

  • Tiocfaidh ár lá
  • member icon

Reputation: 794
  • View blog
  • Posts: 2,880
  • Joined: 31-December 10

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 09:50 AM

I didn't say it would fix it, just showed you there were problems.

What exactly happens when you run the program? Just saying it doesn't work isn't that helpful.

EDIT:
Please post your updated code?

This post has been edited by vividexstance: 28 September 2014 - 09:51 AM

Was This Post Helpful? 0
  • +
  • -

#10 vividexstance   User is offline

  • Tiocfaidh ár lá
  • member icon

Reputation: 794
  • View blog
  • Posts: 2,880
  • Joined: 31-December 10

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 10:08 AM

When I run your program, I get a logic exception thrown from the std::string class.

This is the exception I'm getting:

Quote

terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct null not valid


This line is causing it (199):
string pf = '\0';



Change those single quotes to double quotes.

This post has been edited by vividexstance: 28 September 2014 - 10:08 AM

Was This Post Helpful? 0
  • +
  • -

#11 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2555
  • View blog
  • Posts: 4,739
  • Joined: 30-May 10

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 10:08 AM

Well next you learn how to use a debugger.
$ g++ -g -Wall bar.cpp
bar.cpp: In member function ‘char stack::pop()’:
bar.cpp:67:8: warning: unused variable ‘item’ [-Wunused-variable]
bar.cpp: In member function ‘char stack::stackTop()’:
bar.cpp:87:1: warning: control reaches end of non-void function [-Wreturn-type]
bar.cpp: In member function ‘char stack::pop()’:
bar.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]

$ gdb -q ./a.out 
Reading symbols from /home/sc/Documents/a.out...done.
(gdb) run
Starting program: /home/sc/Documents/a.out 
enter the required expresson
 press a to stop
1 + 2 * 3
a
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid
1  +  2  *  3  
Program received signal SIGABRT, Aborted.
0x00007ffff75523e5 in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64      ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
        in ../nptl/sysdeps/unix/sysv/linux/raise.c
(gdb) bt
#0  0x00007ffff75523e5 in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#1  0x00007ffff7555b4b in __GI_abort () at abort.c:92
#2  0x00007ffff7b90d7d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x00007ffff7b8ef26 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#4  0x00007ffff7b8ef53 in std::terminate() () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#5  0x00007ffff7b8f04e in __cxa_throw () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#6  0x00007ffff7b3b537 in std::__throw_logic_error(char const*) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#7  0x00007ffff7b79ad9 in char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x00007ffff7b79bb3 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#9  0x0000000000401271 in stack::convert (this=0x7fffffffdf70) at bar.cpp:199
#10 0x0000000000401549 in stack::input (this=0x7fffffffdf70) at bar.cpp:245
#11 0x000000000040157a in main () at bar.cpp:252



This shows the program crashed at bar.cpp:199, which in this case is
string pf = '\0';

As well as analysing where it crashed, a debugger allows you to set breakpoints and examine (or even change) variables. You can single step lines of code, or just step over whole functions you know to be working.

When the code path takes an unexpected turn, or a variable has an unexpected value, then you have found a bug.
Whether this is a bug in the code, or a bug in your understanding of the problem, is for you to figure out.
Was This Post Helpful? 1
  • +
  • -

#12 Fizza_94   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 28-September 14

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 10:42 AM

thank you

Was This Post Helpful? 0
  • +
  • -

#13 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: unknown problem, no error but program stop working after 1st call

Posted 28 September 2014 - 11:47 AM

To construct an empty string you just use the default, no argument constructor.
string Empty; // Create an empty string.

...

Empty.clear(); // Delete everything contained in the string.



Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1