•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,009 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,269 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1444 | Replies: 2
![]() |
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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:
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 {
read(word);
} while(strcmp(word, "\n") != 0);
return 0;
}
void read(char word[])
{
cin >> word;
if(strcmp(word, "#") != 0)
cout << word << " ";
else
cout << endl;
} If you're able to split each 'word' into separate strings, then you're already half way there
use the
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.
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). CPP Syntax (Toggle Plain Text)
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.
¿umop apisdn upside down? •
•
Join Date: Feb 2005
Location: 55 26'N 118 46'W
Posts: 181
Reputation:
Rep Power: 4
Solved Threads: 13
Your computer must run quite a bit different than mine then.
Once you've entered your string
char word [80]; cin >> word;
int pntr;
for (pntr = 0; pntr < strlen (word); pntr++)
.... conditional code here
word [pntr] ^= 0x20;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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- A few questions to finish up my project (Pascal and Delphi)
- Very new to VB.Net, please help (VB.NET)
- Capitalize first char of every word in input string (C)
- problem with operator overloading (C++)
- function style cast question (C++)
- String conversion... (C++)
- letter and word counter (C)
Other Threads in the C++ Forum
- Previous Thread: graphics programing in C & c++
- Next Thread: Help needed in designing a c++ program using hashing and linear probing!!


Linear Mode