pointer trouble!

Hey Y'all, I'm having trouble with this homework problem. I got the first part down which is why you see all those p=j and p=1 pointers. But i am stuck on the second part. I'm suppose to:

1. Initialize pc to the beginning of my_cstring.
2. Use it to capitalize the 1st and 5th characters of my_cstring.
3. Use your char pointer to output the integer value of each element of my_cstring (including the 8th element, my_cstring[7]). (hint: you could copy each element to an integer and output it, or use static_cast<int>(...) ).

The problem is I can't seem to get the letters to capitalize. Any help is greatly appreciated!!!

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
#include <iostream>
using namespace std;

int main()
{
    int i = 5, j = 51, k = 62;
    int data[5] = {10, 20, 30, 40, 50};
    char my_cstring[8] = "the fox";
    
    int *p = NULL;
    char *pc = NULL;
	p = &i;
	*p = 1;
	cout << *p << endl;
	p = &j;
	cout << *p << endl;
	p = &k;
	cout << *p << endl;
	p = &data[0];
	*p = 2;
	cout << *p << endl;
	p = &data[2];
	*p = 3;
	cout << *p << endl;
	pc = &my_cstring[0];
	toupper(*pc);
	cout << *pc << endl;
   
    cout << "done"<<endl;
    #ifdef WIN32
    system("pause");
    #endif
    return 0;
}
try to #include <cctype>
1
2
3
	pc = &my_cstring[0];
	toupper(*pc);
	cout << *pc << endl;


1. Initialize pc to the beginning of my_cstring.
Good, you've done that.

2. Use it to capitalize the 1st and 5th characters of my_cstring.
You've done the first, but you also need to do the 5th.

3. Use your char pointer to output the integer value of each element of my_cstring (including the 8th element, my_cstring[7]). (hint: you could copy each element to an integer and output it, or use static_cast<int>(...) ).
You need a loop to traverse the char array, my_cstring. Visit each element, cast it to an int, and print it.
Last edited on
I include the #include <cctype> but everytime I run the program I get a lowercase letter instead of an uppercase letter?
Okay, I figured out how to capitalize the 1st and 5th elements but now I am stuck on the third part. What do you mean to visit each element and cast it as an int?
1
2
3
4
for(pc = my_cstring; pc - my_cstring <= 7; pc++)
{
     cout << static_cast<int>(*pc) << endl;
}
Thanks You guys! Really appreciate it!!
Topic archived. No new replies allowed.