C++ :: How To Capitalize Letter After A Space In Array
Jul 25, 2013
The assignment is to read a data file with a list of names, capitalize the first character of the first and last name by making an array and subtracting 32 from the character, and then outputting the names onto the screen. So far I have:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile ("Names.txt");
[Code] ....
this allows me to read a name, and capitalize the first letter of the first name. How to capitalize the first letter of the last name.
View 2 Replies
ADVERTISEMENT
Oct 28, 2014
Can I capitalize first letter of each word without using arrays ? If yes, how can I ?
View 11 Replies
View Related
Jan 7, 2014
I have a difficulty with string methods for some reason. I tried solving a question from my book, which requires me to capitalize the first letter of every word in a string. I kept trying for maybe two hours yesterday, re-reading the string chapter to see if I'm forgetting a certain method or if something similar was discussed in the examples but I didn't find anything. I also googled it, and found a few answers, none of which I understood. They mostly had keywords or methods I wasn't familiar with. Anyway, here's where I am so far.
class Program {
static string UpperCase(string s) {
int place; string b, st1, st2,st3; char letter;
for (int i = 0; i <= s.Length - 1; i++) {
if (i == 0) {
[Code]....
The code compiles without any errors, but when I enter a string it capitalizes correctly for the first two words and then it starts capitalizing letters in the middle of the words.
View 14 Replies
View Related
Oct 12, 2013
In my code I have a template class.
In the contructor, I create a new array arrray.
A pointer to this array is saved as an attribute.
The purpose of this attribute is that I should be able to call the array from within another function be typing *p or *(p+1) etc.
The only thing I forgot is that the array doesn't exist anymore when the constructor is done, right?
This means the space is no longer reserved for this array and the space is used for other things.
Is there a way to keep the array space reserved (even when the array does not exist anymore at the end of the function)?
View 1 Replies
View Related
Apr 29, 2014
I have a character Array 'Hello'
I want to add a space in whatever space the users chooses.
"Where do you want to add space? --> " 3 String after space is added --> 'Hel lo
View 4 Replies
View Related
Feb 28, 2015
I need to calculate how often each letter appears in a text file from a function that is called from main() with an array of pointers to char and how many pointers there are in the array. The code i have so far is:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
[Code]....
I get no errors and it runs but it gives me the wrong output. I know my array is correct because when i print it in main() it is correct but each letter is incorrectly counted. When i give it the input .txt file of:
This is one line of a string
This is another
This is the third one
Wow heres another one
It counts a as 8
b as 1
c as 3
etc.
I have hand traced it and cant figure out why it isnt giving me correct values
View 4 Replies
View Related
Sep 2, 2014
I am trying to fill an array with blank spaces and instead i get the number 32 over and over, i think this is the ANSI code for that character. how do i get the character itself?
char values[max];
for(o=0;o<=max;o++)
{
values[o]=' ';
printf("%2d ", values[o]);
}
printf("
");
View 1 Replies
View Related
May 14, 2013
How do you find the amount of space in a char array?
View 11 Replies
View Related
Mar 16, 2013
im trying to capitalize every other word. for examples input: hello output: HeLlO
View 5 Replies
View Related
Mar 1, 2015
So this is my homework: a user will enter a line of text, echo the input one word per line and capitalize each word(do not use toupper) and also needs word count and punctuation marks count. I know how to echo one word per line. How to capitalize each word without toupper? and how to do word count?
View 3 Replies
View Related
Apr 7, 2013
I want to do this but do not know exactly how to do it:
Create an array of space ship objects and write a program that continually updates their positions until they all go off the screen. Assume that the size of the screen is 1024 pixels by 768 pixels.
I have begun to write a bit code but the problem is when you want to see the space ship moving step for step on the screen I do not know how to create the ship visible so you can see it is moving. Here's my code so far
Code:
#include <iostream>
using namespace std;
struct SpaceShips
{
int x_coordinate;
int y_coordinate;
[Code ......
View 4 Replies
View Related
May 31, 2013
Write a function that accepts a pointer to a C-String as an argument and capitalizes the first character of each sentence in the string. For instance, if the string argument is "hello. my name is Joe. what is your name?" the function should manipulate the string so it contains "Hello. My name is Joe. What is your name?" Demonstrate the function in a program that asks the user to input a string and then passes it to the function. The modified string should be displayed on screen. Optional Exercise: Write an overloaded version of this function that accepts a string class object as its argument.
#include<iostream>
#include<cctype>
#include<cstdlib>
using namespace std;
void capitalize(char sentence[], int const SIZE);
[Code]...
Not even sure if I'm headed in the correct direction, but I'm getting the following errors:
E:CPT-233Sentence Capitalizer.cpp In function `void capitalize(char*, int)':
34 E:CPT-233Sentence Capitalizer.cpp call of overloaded `strstr(char&, const char[2])' is ambiguous
note E:CPT-233<internal>:0 candidates are: char* std::strstr(const char*, const char*) <near match>
note E:CPT-233<internal>:0 char* std::strstr(char*, const char*) <near match>
what I'm doing wrong?
View 2 Replies
View Related
Nov 3, 2014
So first I have to display a 2D array with all 0s, which is pretty easy.
#include <iostream>
using namespace std;
int main (){
int array[5][5];
for(int a=0; a<5; a++){
for(int b=0; b<5; b++){
array[a][b] = 0;
[Code] ....
So this displays
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Next, this is where it gets confusing. I have to create a virtual creature by storing a letter into a random position in the array (the array can be up to 20x20 in size). Then make a function that searches the array for creatures, so it would search for that character. When it finds a creature, it should randomly decide to either move the creature to an adjacent position, or have it stay where it is. After, it should ask the user to create a new creature, or quit.
So how would I go about adding & modifying the current code to achieve what is listed above?
View 2 Replies
View Related
Nov 14, 2014
I've been agonizing over this all day. The assignment is to capitalize every other word in a user input string.
My logic is as follows:
1. I have the program get each character until it encounters white space (using for loop)
2. Then it should capitalize each character after the white space until it encounters another white space (using while loop).
My problem though is when i try to create a condition for while loop i have to terminate is when white space is encountered, but the very first character to start the while loop is a white space..
I was told to define boolean values, but after trying a few boolean conditions I'm still stuck..
Code:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
[Code] .....
View 5 Replies
View Related
Feb 26, 2013
I'm trying to write a program that capitalizes every other word of a user output. (ex: if input is "i love you", the output is "i LoVe YoU").
I am using a for loop (although an if loop might be easier?) and I'm assuming that it is possible to write this program using a for loop (although I may be wrong--maybe only if loops can write this program). I have everything down EXCEPT the last step where I have to print the entire sequence. What i have so far is:
Code:
#include <cs50.h>
#include <stdio.h>
#include <string.h>
{
// get user input
printf("Type a sentence: ");
string s = GetString();
[Code] .....
The code above basically only prints out the capital letter (ex: input is "hello", output is "EL"). I don't know how to print out the entire sequence.
View 2 Replies
View Related
Sep 23, 2013
how can my program read if a letter is inputted again it prompts "letter inputted already"? heres my code:
Code:
#include <stdio.h>
#include <string.h>
#include <conio.h>
[Code].....
View 8 Replies
View Related
Nov 9, 2013
I am trying to print out the letter frequency of a vector that the user inputs and what number that letter is in the ASCII. I am supposed to say, for example: "w" which is ASCII 119 occurs 2 times. How to do this?
View 1 Replies
View Related
Apr 27, 2013
i`m currently racking my brains out over this issue. How do i go about the x as the first occurrence of the letter?
lets say helxo , x is the 2nd occurrence of l. I will want to change back x into l
i have replaced it with x in the earlier step with this code...
string everySecondChar(const string &s,char source,char distance)
{
string t(s);
for(std::string::size_type even =0,pos=t.find(source,0);pos!=std::string::npos;pos=t.find(source,++pos))
{
[Code]....
i would like to reverse the process now, letting x becoming l again!
View 10 Replies
View Related
Nov 13, 2013
I am new to c++. I am writing a program that reads in a text file and gives a count of how many times each letter appeared in the file. I got it to read the text file and do the letter count. B
X = 102
Y = 126
Z = 165
etc...
THAT IS WORNG
The sample output should be
E = 165
T = 126
A = 102
O = 93
etc...
I got it to sort from lowest to highest for the frequency, but cant seem to get the appropriate letter assigned to it.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
[code].....
View 1 Replies
View Related
Apr 21, 2013
Supposed i have a word hammer.
how am i suppose to search for the 2nd occurrence of the letter and then replace it with x?
example hammer will become hamxer
I thought about using replace for it, however i`m lost on how to find 2 occurrences of the same letter in the word.
string formatEncrypt(string message) {
int msgLength=message.length();
for(int i=0;i<msgLength;i++) {
if(message[i] == 'j' {
message[i]='i';
[Code] .....
at line 31 i tried to put a z into the alphabet that occurs twice.
this is what i have done so far
example: hello world
It will turn out as helzlo world
However i want to make the output appear as helzo world
View 6 Replies
View Related
May 11, 2014
How would I detect if any letter key is pressed. Would I have to use GetAsyncKeyState() for every letter key? Or could I have some kind of loop going through all the hexadecimal values for every letter? I don't know how I would go through hexadecimal values with a loop.
View 6 Replies
View Related
Nov 18, 2014
I need to count how many times letter appears in a text. I know that for default letters from 'a' to 'z' and from 'A' to 'Z' there is an interval. But I need also Lithuanian letters, such as ž,č,ę. I wrote this method: (it accepts char code and checks whether that char is a letter)
bool eilutė::YraRaidė(int kodas)
{
if(kodas >= 'a' && kodas <= 'z') {
return true;
[Code]....
As you can see, a lot of checking in switch statement. I use 256 for this reason to have the same effect as unsigned char. But maybe there is a way to shrink down this method, or use some library?
View 7 Replies
View Related
Jan 21, 2013
I just would like to turn this into cpp:
string eg("azertyFTW");
if(eg[one of the letters contained in this string] == 'c') {
cout << "eg has the letter c in it";
} else {
cout << "not this time :(";
}
View 4 Replies
View Related
Feb 29, 2012
I wanna know why the program doesnt show "Invalid Letter Entered" when i enter any letter other than A S D or M
//Processing the data
if (letter== 'A'||'S'||'M'||'D')// checking Add, subtract, multiply or divide {
if (letter== 'A')//Adding the integers
cout<<"Adding two integers = "<<first + second<<endl;
else if (letter== 'S')//Subtracting the integers {
[code]......
View 1 Replies
View Related
Sep 20, 2014
how to input with space what i mean is like this, for example:
Product Code: 0000001
Product Name: Mobile Phone
if the users input is like that in the (Product Name)it will skip the next input that is the
Price: Quantity: 100
Manufacturer: Alcatel
something like that...
Heres the code
Code:
if(b<=10)
{/*Start for IF Statement*/
for(a=1;a<=b;a++)
{/*Start of FOR loop*/
printf("
");
printf("Product Code : ");
scanf("%s", &prod_code);
}
[code]....
View 14 Replies
View Related
Dec 2, 2014
I used pointer(or is it not?) to make it one part only alphabets and the other one digits. The coding, calculate_charges.c and the open file, customer.txt are attached at the end of the post.
Code:
#include <stdio.h>
#include <string.h>
#define SIZE 3
void trimback(char input[], int strnameindex);
void trimfrnt(char input[], int strnameindex);
}
[code]....
View 3 Replies
View Related