By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

problem with c++

P: n/a
Hello!

I have a little problem with one thing.

Write the program, which change every second letter on the big letter, in
every word which I "cin" from keyboard.
For example:

John has a cat.

JOhn hAs a cAt.
Please help me!
========
sebussebus
Dec 12 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a

Sebu¶ wrote:
Hello!

I have a little problem with one thing.


Your problem is not with C++, it's with your homework.

For that problem, you'll find the answer here:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

Cheers,
Andre

Dec 12 '05 #2

P: n/a

Sebu¶ wrote:
Hello!

I have a little problem with one thing.


Your problem is not with C++, it's with your homework.

For that problem, you'll find the answer here:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

Cheers,
Andre

Dec 12 '05 #3

P: n/a
Sebu¶ wrote:
Hello!

I have a little problem with one thing.
Which "thing" do you have the problem with?
Write the program, which change every second letter on the big letter, in
every word which I "cin" from keyboard.
For example:

John has a cat.

JOhn hAs a cAt.
Please help me!


Help you, how? Write it for you?
Dec 12 '05 #4

P: n/a
I have program:

===========
#include <string>
#include <iostream>
#include <cctype>
#include <string>

using namespace std;
int main( )
{
string s;
do
{
cin >> s;
s[2]=to_upper(s[2]);
cout << s << ' ';
}
while(cin);
cout << endl;
}
=========

But DevC++ write me:
'to_upper' undeclared (first use this function).

I can't see it where it isn't undelclared?


Help you, how? Write it for you?

Dec 12 '05 #5

P: n/a
Always post the code if you have it right away. Saves you from getting
the replies you got.

Sebus wrote:
I have program:

===========
#include <string>
#include <iostream>
#include <cctype>
#include <string>
You already included <string> (first line)

using namespace std;
int main( )
{
string s;
do
while( cin >> s ) ...
{
cin >> s;
s[2]=to_upper(s[2]);
to_upper() doesn't exist. It's toupper().
Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...
cout << s << ' ';
}
while(cin);
cout << endl;
}
=========

But DevC++ write me:
'to_upper' undeclared (first use this function).

I can't see it where it isn't undelclared?
Help you, how? Write it for you?


Cheers,
Andre

Dec 12 '05 #6

P: n/a
Sebus wrote:
I have program:

===========
#include <string>
#include <iostream>
#include <cctype>
#include <string>

using namespace std;
int main( )
{
string s;
do
{
cin >> s;
s[2]=to_upper(s[2]);
cout << s << ' ';
}
while(cin);
cout << endl;
}
=========

But DevC++ write me:
'to_upper' undeclared (first use this function).

I can't see it where it isn't undelclared?


toupper(), not to_upper().
Dec 12 '05 #7

P: n/a
Hi

in*****@gmail.com wrote:
Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...


Surely you meant three.

Markus

Dec 12 '05 #8

P: n/a
Not three, but one it's ok.
The every second letter have to toupper. :)

I have one more thing:
==

write program, which rename name of files (all files) in catalogue "test",
to add "0" to the name of file.
For example:

we have three files:
d://test//file1.dat
d://test//file2.dat
d://test//file3.dat

and we have to have:

d://test//file10.dat
d://test//file10.dat
d://test//file10.dat
I used "rename" but i don't know what about mask, for example:
rename(*.*,*0.*).

Could You help me???

Surely you meant three.

Markus

Dec 12 '05 #9

P: n/a

Markus Moll wrote:
Hi

in*****@gmail.com wrote:
Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...


Surely you meant three.

Markus


Never said I could count! :p

But yes, this also points out another mistake by the OP - s[2] is the
THIRD letter, not the second one. I based my reply on the desire to
modify the second letter.

Cheers,
Andre

Dec 12 '05 #10

P: n/a
Markus Moll <mo**@rbg.informatik.tu-darmstadt.de> schrieb:
in*****@gmail.com wrote:
Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...


Surely you meant three.


I'm quite sure he didn't.

Markus
Dec 12 '05 #11

P: n/a

Markus Moll skrev:
Hi

in*****@gmail.com wrote:
Also note that accessing s[2] will cause a crash (or undefined
behaviour at best) if the string entered is less than 2 characters...
Surely you meant three.


Why is that so? If s only has one character, accessing the second
character as above is surely undefined behaviour. While many (all?)
std::string implementations always have room for the null-character (in
case the user calls c_str()), this is not required.

/Peter
Markus


Dec 12 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.