Some kind of mistake?

hello!

I built a class, compiled it with no problems but windows dos wonn't let me execute the program, it interrupts it...
Am I allocating memory incorrectly or something?
I really don't know what could be wrong...

this is the class I wrote:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

#include<iostream>
#include<cstdio>
using namespace std;

class stuff{
      
      char what[80];
      int how_many;
      double price;
      bool got;
public:
       void init();
       
       void put_what(char *str){*what=*str;}
       void put_how_many(int n){how_many=n;}
       void put_price(double p){price=p;}
       
       int get_how_many(){return how_many;}
       double get_price(){return price;}
       char *get_what(){return what;}
       
       char *gots(){ if(got)return "Yes";
                     else return "No";}
       void display();
       void define();
};


and there are it's member functions:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//Initializing the class
void stuff::init()
{
     *what=0;
     how_many=0;
     price=0;
     got=0;
}

// Putting user-defined variables in the class
void stuff::define()
{
     char *str;
     int n;
     double p;
     char* g;
     
     cout<<"\n Insert item name: ";
     cin>>gets(str); put_what(str);
     cout<<"\n Insert number of items needed: ";
     cin>>n; put_how_many(n);
     cout<<"\n Insert price of item: $";
     cin>>p; put_price(p);
     cout<<"\n Has the item already been bought? ";
     cin>>gets(g);
                  if(strcmp(g,"Yes")) got=0;
                  else got=1;
}

// Displaying the contents of the class on the screen
void stuff::display()
{
     cout<<"\n Item: "<<get_what();
     cout<<"\n Number of items needed: "<<get_how_many();
     cout<<"\n Price of item: $"<<get_price();
     cout<<"\n Has the item already been bought?"<<gots();        
}


Can you Help me?
*what = 0

and

*what = *str

do not do what you want. They copy a single character. clearly you are wanting what to be a string.
Topic archived. No new replies allowed.