My assignment says I'm supposed to read in an address all on one line separated by pound signs (eg jane doe # p.o. box 123 # new york, new york 97229 #) and output it with correct capitalization and in proper address format like:

Jane Doe
P.O. Box 123
New York, New York 97229

Also we have to use character arrays, no strings, and cannot use global variables. I've gotten it to output in address format, but I have no idea how to capitalize all the letters that need to be uppercase. This is what I have so far:

#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstring>

using namespace std;

void read(char word[]);

int main ()
           cout << "Enter address: \n";
           char word[40];

           do {
            } while(strcmp(word, "\n") != 0);

            return 0;

void read(char word[])
            cin >> word;
            if(strcmp(word, "#") != 0)
                     cout << word << " ";
                     cout << endl;

Recommended Answers

All 2 Replies

If you're able to split each 'word' into separate strings, then you're already half way there

use the toupper function on the first character of that word, to generate the uppercase equivalent of that character (If an uppercase equivalent is available).

word[0] = toupper( word[0] );

This won't solve the problem of converting all letters in acronyms to uppercase; eg, a string of "p.o. box" will only be converted to "P.o. Box", since there is no whitespace character between the 'p' and the 'o'.

- Depending on the exact requirements of your assignment, you may need to do some additional string parsing for characters which follow punctuation.

I've gotten it to output in address format

Your computer must run quite a bit different than mine then.

Once you've entered your string

char word [80];
cin >> word;

or whatever size you think you need, then just cycle through all the characters changing # to carriage returns and anything after spaces and periods to upper case

int pntr;
for (pntr = 0; pntr < strlen (word); pntr++) 
     .... conditional code here
        word [pntr] ^= 0x20;

Invent whatever looping operation you like with DO, FOR or WHILE with either conditionals or SWITCH.

If your code would have at least output in the proper format I would have given you the solution, but it doesn't come anywhere near that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.