Tellalca 19 Posting Whiz in Training

I think it is stored as

names[0]="Dean"// pointer to the starting character of the string "Dean"
names[1] ="Viky"// pointer to the starting character of the string "Viky"

And "Dean" and "Viky" is hold as two another array of characters in another place in memory.

Tellalca 19 Posting Whiz in Training

I have tried to implement a stack class but i got stupid errors. There is a stupid error i know but i couldnt find it.

#ifndef STACK_H
#define STACK_H

/*Manual implementation of Stack class.
  By this way it will be possible to learn the advantages of Stack 
  data structure over others. This is the header file of class Stack */

const int maxstack=10; //A small value to be tested as a limit of the stack

class Stack
{
public:
	Stack(); //Constructor
	bool empty() const; //constant function returns true if the stack is empty otherwise returns false
	
	Error_code pop(); /*Function tries to pop the value from the stack if the stack is not empty
					  and returns Error_code*/

	Error_code push(const Stack_entry &item); /*function tries to push the value of constant item to 
											  the top of the stack and returns Error_code*/

	Error_code top(Stack_entry &item) const; /*function tries to copy the value of the top of the
											 stack into the item and returns Error_code */

private:
	int count; // counts the number of values existing in the stack

	Stack_entry entry[maxstack]; //the decleration of the stack that will hold the values.
};

#endif
#include "stack.h" //Imports the Stack header file containing the declaration of the member functions

Stack::Stack()
/*The stack is initialized as empty */
{
	count=0;
} //end of Stack::Stack constructor

Error_code Stack::push(const Stack_entry &item)
/*If the stack is full then the error code overflow is returned
else the item is pushed to the top of the stack and return error code …
Tellalca 19 Posting Whiz in Training

I found the mistake.

int memberNum=0;
member *members=new member[memberNum];

So i allocate memory for "0" member and try to do operations on the nonalocated memory.

Tellalca 19 Posting Whiz in Training

Please help me, I'm getting this error very frequently.

Tellalca 19 Posting Whiz in Training

If you can send the reorganized .cpp and .h files maybe we can help easier.

Tellalca 19 Posting Whiz in Training

Hello everyone, i was just trying something when i got the error. I debugged and it says string password <Bad Ptr> and that password string have more than lets say 100000 childs of characters in it. I used the string::resize() member function but it doesnt seemed to solve the problem.

I couldn't find the solution and i have that <Bad Ptr> error a lot in my programs. What is wrong with it?

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

struct member
{
private:
	int id;
	string password;
	string name;
public:
	member()
	{
		id=0;
		password.resize(5);
		password="0000";
		name="Default";}

	member(int Id, string Password, string Name)
		:id(Id),password(Password),name(Name)
	{}

	void setId(int Id)
	{
		id=Id;}

	void setPassword(string Password)
	{
		password=Password;}
	
	void setName(string Name)
	{
		name=Name;}

	int getId()
	{
		return id;}
	
	string  getPassword()
	{
		return password;}
	
	string getName()
	{
		return name;}
};




int main()
{
	int state=1;
	int memberNum=0;
	member *members=new member[memberNum];

	while(state)
	{
		cout<<"To create a new member type 1, to view a profile type 2, to exit type 0:";
		cin>>state;
		if(state==1)
		{
			memberNum++;
			int id;
			string name;
			string password;

			
			cout<<"Enter the ID, name and password in order:";
			cin>>id>>name>>password;
			members[memberNum].setPassword(password);
			members[memberNum].setName(name);
			members[memberNum].setId(id);
		}
	}



	return 0;}
Tellalca 19 Posting Whiz in Training

That is true too but i found my mistake. checkSame() member function returns 0 if it is a different from the words in word[] array. So i changed the if(test.checkSame()) to

if(!test.checkSame())

Thanks anyway.

Tellalca 19 Posting Whiz in Training

Maybe it will be better to declare pi, radius and area as double or float.

If you want to calculate areas of more circles, you can try a loop and then add the areas to the sum.

Tellalca 19 Posting Whiz in Training

I cannot assign my rawWord value to the string array. The program reads a value from testText.txt and then edits it. Then this manipulated char rawWord[20]'s value must be assigned to the string array word. When i debug i see that rawWord is edited correctly, but when it comes to addWord(), the program does not assign the value to the string word[] array. Can you help me with this problem please.

This is my first post, so if i have mistakes sorry.


#ifndef WORDS_H
#define WORDS_H

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

class words
{
	
	int arraySize;
	string word[1000];
	char rawWord[20];
	
	public:
	words(int arraySizeI=1 ): arraySize(arraySizeI){}

	void readWord(fstream & txtPointer)// member function that just reads the data and hold it in the rawWord[]
	{
		txtPointer>>rawWord;
	}
	
	bool checkWord()
	{
		if( !((rawWord[0]>64 && rawWord[0]<91) || (rawWord[0]>96 && rawWord[0]<123)) )// check if it is a word starting with
			return 0;																  // an alphabet
		else // if it is a acceptable formed word then enter this
		{
			return 1;
		}
	}

	void editWord()
	{
		for(int i=0; i<20; i++)
		{
			if( !((rawWord[i]>64 && rawWord[i]<91) || (rawWord[i]>96 && rawWord[i]<123)))
			{
				rawWord[i]=0;
				break;
			}
			else if( (rawWord[i]>64 && rawWord[i]<91) )
				rawWord[i]+=32;
		}
	}
	bool checkSame()
	{
		bool same=0;
		for(int i=0; i<arraySize; i++)
		{
			if( word[i]== rawWord)
			{
				same=1;
				return same;
			}
		}
		return same;
	}

	void addWord()
	{
		word[arraySize-1]=rawWord;
		arraySize++;
	}
};

#endif
#include "200611004_lab2.h"

int main()
{
	bool status;// holds 1 if word is acceptable else …
tux4life commented: Well done on the code tags, for your first post. +8