How would I make this char array uppercase (given my code)

How would I make this char array uppercase (given my code)
in line 17 if possible.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

int main(int argc, const char * argv[])
{

    char charArr[50];
    * charArr = NULL;
    cout << "Please enter in a string";
    cout << endl; 
    cin.getline ( charArr,'NULL');
    cin.clear();
    cin.ignore(numeric_limits<streamsize> :: max(), '\n') ;
    char * c = NULL;
    for (c = charArr; *c != '\0'; c++) {
        cout << *c << endl;
    }
    return 0;
}
Either use the toupper function (easiest), or it is possible to do math with the char value - have a look at an ascii table.

http://www.cplusplus.com/reference/cctype/toupper/
http://www.cplusplus.com/doc/ascii/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main(int argc, const char * argv[])
{

    char charArr[255];
    * charArr = NULL;
    cout << "Please enter in a string";
    cout << endl; 
    cin.getline ( charArr,'NULL');
    char * c = NULL;
    for (c = charArr; *c != '\0'; c++) {
        cout << (char)toupper(*c) << endl;
    }
    return 0;
}
Last edited on
C++ Program Enter string and convert it to upper case
here is the link...
http://cbtsam.com/cppl2/cbtsam-cppl2-142.php


// WAP a program to enter string including spaces in C++ and convert it to UPPER Case without using built-in Function. For eg. cbtsam -> CBTSAM
#include <iostream.h>
#include <conio.h>
#include <string.h>
void main()
{
char st[50];
cout<<"Enter String : ";
cin.getline(st,50);
int length=strlen(st);
for (int n=0;n<length;n++)
{ if (st[n]>=97)
cout<<char(st[n]-32);
else
cout<<st[n];
}
}
Last edited on
Topic archived. No new replies allowed.