Question on how to make something loop

So I got this program from a book and what I like to do is change it to do things I previously learned to do. The program uses toupper. I would like to have you be able to enter a string, see the output, then do it all over again until you type in "exit". I already changed the program in an attempt to make it happen, but so far no luck. What am I doing wrong?

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
38
39
40
41
42
43
44
45
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

void toupper(char szTarget[], int nTargetSize)
{
    for(int nT = 0;
           nT < (nTargetSize - 1) && szTarget[nT] != '\0';
              nT++)
    {
        szTarget[nT] = toupper(szTarget[nT]);
    }
}

int main(int nNumberofArgs, char* pszArgs[])
{
    cout << "This program accepts a string\n"
         << "from the keyboard and echoes the\n"
         << "string in all caps.\n" << endl;
         
    char szString[256];
    int cExit('exit');

    while(szString[256] != cExit)
    {
        cout << "Enter string; ";
        cin.getline(szString, 256);

        toupper(szString, 256);

        cout << "All caps version: <"
             << szString
             << ">" << endl;
             break;
    }
        if(szString, 256 == cExit)
        {
            cout << "Exiting" << endl;
        }

    system("PAUSE");
    return 0;
}
What the hell is while(szString[256] != cExit) and if(szString, 256 == cExit)?
Use strcmp for char array or std::string::compare for std::string class (which you should instead of char here).
Last edited on
Topic archived. No new replies allowed.