i'm getting the segmentation fault at 25th line but i don't understand why?
Are you asking us if you don't understand, or are you telling us you don't understand?
p[top]=a;
If this causes a segFault, then you are trying to write to a location that is not yours to write to. Whatever the size of the array p is, top is too big. What's the value of top? What size is the array p?
I'm telling that i don't understand?
In the initialize function i already specified top=-1 and in the push function i first incremented top(top++) and then accessed p[top]. please help me with the problem.
At the point in the code where the segFault happens, what's the value of top and what size is the array p? Don't guess. Check. Either use a debugger, or put some code in to tell you.
but how do i check i running a windows system wherein i don't get a dedicated debugger which shows me value and size of array. i use dev-cpp on win 7. can u help me by checking it on your machine please. or any solution using dev-cpp. and i guess the array is of suitable length. help lease. thanks in advance.
Here's an example of a popular way to determine the value of a variable at a given point. cout << "The value of top right now is " << top << endl;
and i guess the array is of suitable length
That's impossible. That's the whole point. If the segault is on the line you said, you're trying to write outside the array. If the array was of a length suitable to where you're trying to write, everything would be fine.
If you have to write "help please " in every post ankit, you're doing something really wrong.
Why aren't you printing in every step or using gdb ?
use std::cout << after every step to see if your code is behaving the way you want.
better yet use gdb but i am guessing you don't want to take that pain.
It's as if you want others to find the problem for you and fix it for you ? Are you just trying to finish up a code and submit or to actually learn ??
hello navderm i actually want to learn but i'm very new to pointers and frequently get segmentation faults but those were generally due to accessing null pointers. but this the pointer isn't set to null and i also tries cout statements in the initialize(line 15) as well as push(line 25) code and the top is correctly set to 0 for the first element, and also the size is set 2*len appropriately. I'll try to check it out on gdb but currently not having any linux system with me. Thanks for help @navderm.
char *input=newchar[2*len];
input=NULL; //leak
//...
input=data; //make up your mind
input[2*len-1]=')';
cout<<"Input String provided"<<endl;
cout<<input<<endl<<endl; //Not '\0' at the end
global, global everywhere.
You didn't `initialize' stack op. That should be the work of a constructor
Very very thanks ne555 i sorry for doing such mistakes actually i'm newbie and just learning cpp and pointers is my fourth chapter. I'll try reducing globals and optimize the program.
Thanks again for guiding me.