I got nothing...

Hi everyone I have a class where I have a function that converts the string(pointer) to upper caps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Name
{
  private:
    char* ch;
    int size;
  public:
    // construct, destruct, copy construct etc
    Name capitalize()const;
};

// this is where I am stuck and confused.
// I need to return an object of Name to upper case
Name Name:: capitalize()const
{
  Name temp;

  // not sure what to do here

  return temp;
}


any help is appreciated
It's pretty straightforward. 'temp' should be a copy of the current object ('this'), then you just go through temp's string and convert all its characters to uppercase.
Updated (eypros coments made me realize)

all three will not work ....
I am not getting the concept for sure

1
2
3
4
5
6
7
8
Name Name::capitalize()const{	
  Text temp;

  for(int i = 0; i<temp.Size; i++)
  {
          // smthing in here }
  return temp;
}


Last edited on
You never initialize temp. That means it's default initialized, so since you don't specify any constructor a constructor by the compiler will be provided that initialize each data member to it's default value. Depending on your compiler this would be:
1
2
ch = 0;
size = 0;
or junk (arbitrary data). This is not what you want.

Also what is bufferSize; You never declare it. That goes for buffer also.

1)Define a constructor and use this to initialize temp.
2)Then use a loop like above but using your actual data members (ch and size) not other ones like buffer etc and capitalize every character you find.
3)Then return this temp object
Last edited on
Ah got it,

Thanks epryos for your help
Topic archived. No new replies allowed.