C :: Capitalize Letter Without Using Arrays

Oct 28, 2014

Can I capitalize first letter of each word without using arrays ? If yes, how can I ?

View 11 Replies


ADVERTISEMENT

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 View Related

C# :: Capitalize First Letter In Every Word In A String?

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

C++ ::  2D Arrays - Creating Virtual Creatures By Storing A Letter Into Random Position In Array

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

C :: Capitalize Every Other Word?

Mar 16, 2013

im trying to capitalize every other word. for examples input: hello output: HeLlO

View 5 Replies View Related

C :: How To Capitalize Each Word

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

C++ :: Capitalize First Character Of Each Sentence In String

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

C++ :: Capitalize Every Other Word In A User Input String

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

C :: Program To Capitalize Every Other Word Of User Input

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

C :: Know If Letter Is Inputted Twice

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

C++ :: Letter Frequency For A Vector

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

C++ :: Replace 2nd Occurrence Of Letter?

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

C++ :: Letter Frequency Count

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

C++ :: How To Replace 2nd Occurrence Of A Letter With X

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

C++ :: Detect If A Letter Key Is Pressed?

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

C/C++ :: Determine That Char Is A Letter

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

C++ :: One Letter Of A String Comparison

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

C/C++ :: Why Invalid Letter Not Showing

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

C++ :: Finding Names That Start With A Certain Letter

May 30, 2013

I am doing a homework assignment. I do not want the complete answer, just a hint. I have to load a file of names into an array, display the names, then sort the names alphabetically, display them again, then list how many names start with certain letters. I have everything done but how to display how many names start with a certain letter.

Here are the names:

Collins, Bill Smith, Bart
Allen, Jim
Griffin, Jim
Stamey, Marty
Rose, Geri
...........

And here is the code I have so far.

Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <algorithm>

[Code] ....

View 5 Replies View Related

C :: How To Read Only The First Capital Letter From A File

Dec 25, 2014

I'm supposed to count the number of first capital letters in a string. I've written a code that counts every uppercase letter, and it turns out that this is not what the assignment is about. For example, the input "JAMES, How Are you?" should return an output of 3 (mine would return 7 in this case). Only J, H, A need to be counted.

Code:

#include <stdio.h>
#include <string.h>
#define MAX 100
void WriteToFile() {
FILE *f = fopen("text.txt", "w");
char c;
while((c = getchar()) != EOF) {

[Code]...

How do I fix this?

View 2 Replies View Related

C :: How To Initialize A Variable That Is Not A Letter Or Number

Feb 25, 2014

In C how can I initialize a variable that is not a letter or number? For example with a number I can :

Code:

int i = 5;
for ( i = 0; i <=5; i++ );
printf( "%d", i ) This would display a row of 5's

but what if I wanted to display a row of -----? What I am trying to do is read in a simple txt file, around the file I want ----1----2-----3 ect ect on the top ----a----b-----c down the side Then I want to be able to change the file at lets say position c2 and save it. This is the early stages of my attempt to set up a editable table.

View 3 Replies View Related

C :: Loop Function That Scans For A Letter

Apr 29, 2013

How can loop this function so it keeps asking the user till they enter a correct letter that can be found in the unscrambled array?

Code:
char LetterGuessed(char unscrambled[]) {
char c;

printf("+-----------------------------+
");
printf("| Please guess a letter: |

[Code] .....

View 1 Replies View Related

C++ :: Change First Letter Of Each Name To Upper Case?

Oct 2, 2013

I can get the first letter to change if there is only one word. But if there are two words it wont change and display the second word's first letter and I'm not sure why.

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

[Code].....

View 3 Replies View Related

C++ :: How To Loop Through A String And Uppercase Each Letter

Apr 28, 2013

tell me how to loop through a string and uppercase each letter?

View 1 Replies View Related

C/C++ :: Numeric Score To Letter Grade

Feb 9, 2015

The code runs but asks me for my score twice then just comes to an abrupt end with out giving me a letter grade.

#include <stdio.h>
int getScore(void);
char convertGrade(int numscore, char letterGrade);
void showGrade(int numscore, char letterGrade);

// Function to prompt for and read a numeric score
// Returns an integer score as read in using scanf

[Code] ....

View 12 Replies View Related

C/C++ :: GPA Calculator When Given Letter Grade For Various Courses?

Jul 5, 2014

Write a program which is used to calculate the GPA based on the grades for different courses input by user. User should be able to use this to enter grades for as many courses as he wants unless he wants to quit. (you may consider using some loop). Once user has completed entering of data, the program should be able to provide a feedback to the user about the GPA. A is equal to 4, B is equal to 3, C is equal to 2, D is equal to 1, rest are 0. Use minimum 5 course to demonstrate working of your code.

Here is an example (User input is in italic and bold):

Would you like to enter grades: Y

Please enter the course name: COSC1301

Please enter your grade: A

Would you like to enter more grades: Y

Please enter the course name:ITSE1301

Please enter your grade: B

Would you like to enter more grades: Y

Please enter the course name:ITSE2409

[code]....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved