| | |
Capitalize first letter of word
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
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:
C++ Syntax (Toggle Plain Text)
#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? Your computer must run quite a bit different than mine then.
Once you've entered your string 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 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.
Once you've entered your string
C++ Syntax (Toggle Plain Text)
char word [80]; cin >> word;
C++ Syntax (Toggle Plain Text)
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.
![]() |
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!!
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





