Need help creating function that capitalizes a char array!

I am stuck on a part of my final project for Introduction to C++ class. This is what it tells me to do.

Write a function called strUpper. This function should accept a pointer to a string as its argument. It should convert each character in the string to an uppercase letter.


This is what I have come up with, but it does not work properly.
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>
using namespace std;

void strUpper(char*);

int main()
{

	const int SIZE = 11;
	char test[SIZE];
	cout << "Enter a string: ";
	cin.getline(test, SIZE);
	strUpper(test);
	cout << test;

	
	return 0;
}
void strUpper(char *itest)
{
	int count = 0;
	while (*itest != '\0')
	{
		cout << toupper(*(itest + count));
		count++;
	}
}


Any help with what I'm doing wrong and how to fix it would be much appreciated!


while (*itest != '\0')

When is that loop ever going to end?
Wow I feel stupid.

I changed it, and it still gives me weird output.

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

void strUpper(char*);

int main()
{

	const int SIZE = 11;
	char test[SIZE];
	cout << "Enter a string: ";
	cin.getline(test, SIZE);
	strUpper(test);
	cout << test;

	
	return 0;
}
void strUpper(char *itest)
{
	int count = 0;
	while ((*(itest + count)) != '\0')
	{
		cout << toupper(*(itest + count));
		count++;
	}
}


http://www.cplusplus.com/reference/clibrary/cctype/toupper/

The value is returned as an int value
Last edited on
This is what I have come up with.

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

void capitalize(char*);

int main()
{
	const int SIZE = 11;
	char yeah[SIZE];

	cout << "Enter a string: ";
	cin.getline(yeah, SIZE);
	
	cout << yeah << endl;
	
	capitalize(yeah);

	cout << endl;

	return 0;
}

void capitalize(char *yeah)
{
	int count = 0;
	while((*(yeah + count) != '\0'))
	{
		
		cout << putchar(toupper(*(yeah + count)));
		count++;
	}
}


I can not figure out why it is printing the ASCII code number after each letter. Any explanation or help would be much appreciated!
I figured it out! Thanks for all the help, it is much appreciated!
Topic archived. No new replies allowed.