-
help help
Hi Everyone,
I am j4me.
I am new to programming. Can someone assist me with these questions;
1. How to manipulate a string case e.g
if the user typed: tOdAy iS suNny. I would like to change this sentence to: Today Is Sunny.
2. validation: I am using isdigit and isalpha but still having problems with them.
Thanks in advance everyone for your assistance. I will truly appreciate it.
oh, I am using C++
Last edited by j4me; 11-23-2007 at 03:57 AM.
Reason: I forgot to write the language
-
DKyb
-------------------------------
Life is a short warm moment -
Death is the long cold rest.
Pink Floyd
-------------------------------
-
try to use isupper islowwer & tolower and toupper to do this
-
changing case
Hi
Thanks for your reply.
However, I am still not clear on the solution.
I am able to input a sentence from any user and change the entire sentence into caps but I don't know how to change the first letter of every word into cap and then output the sentence.
I am trying to creat a code to do this.
-
Algorithm:
Set startOfWord to true.
Loop through each letter:
- if a space, set startOfWord to true.
- if not a space:
-- if startOfWord is true, call toupper on the letter.
-- if not startOfWord, call tolower on the letter.
-
thanks
Thanks alot.
I am going to try this out.
-
-- if startOfWord is true, call toupper on the letter, set startOfWord to false.
-- else if not startOfWord, call tolower on the letter.
-
I could say that I left that for j4me to figure out. But, alas, Amahdy caught me.
It was my one mistake for the day.
-
Hi everyone
Does anyone have any simple idea how to generate the periodic table in Cpp?
-
Chemistry periodic table did you mean ?
There is no constant function that can make this, and I don't think you can do that without inline coding ... or what did you meant exactly ??
-
Chemistry Periodic table
Well, I was trying to find a shorter way of writing it in cpp. Anyway, I am finish coding it.
-
 Originally Posted by j4me
Hi Everyone,
I am j4me.
I am new to programming. Can someone assist me with these questions;
1. How to manipulate a string case e.g
if the user typed: tOdAy iS suNny. I would like to change this sentence to: Today Is Sunny.
2. validation: I am using isdigit and isalpha but still having problems with them.
Thanks in advance everyone for your assistance. I will truly appreciate it.
oh, I am using C++
try this it may slove ur issue.
void main()
{
char name[14]="tOdAy iS suNny";
char prev = " ";
char next;
int i=0;
cout<<name<<endl;
while(name[i])
{
if(prev == " " && islower(name[i]))
name[i]=toupper(name[i]);
else
{
if(isupper(name[i]))
name[i]=tolower(name[i]);
}
prev=name[i];
i++;
}
cout<<name<<endl;
}
-
This declaration will not compile:
char prev = " ";
You're declaring a single char, but initializing it with array of two chars: the space and the nul. Better use
char prev= '\b';
Danny Kalev
-
Actually there is some compilers who just generate a warning and ignore it,, by just adjusting it like if it was : char prev=' ';
Danny is right, you should not use it like that to not get such error :
Code:
if(prev == " " && islower(name[i]))
this if condition will be for ever FALSE as Danny said, prev is char, and a char can never be equal to 2 char .
-
 Originally Posted by Amahdy
Actually there is some compilers who just generate a warning and ignore it,, by just adjusting it like if it was : char prev=' ';
Danny is right, you should not use it like that to not get such error :
Code:
if(prev == " " && islower(name[i]))
this if condition will be for ever FALSE as Danny said, prev is char, and a char can never be equal to 2 char .
use function
int isspace( int ch );
The isspace() function returns non-zero if its argument is some sort of space (i.e. single space, tab, vertical tab, form feed, carriage return, or newline). Otherwise, zero is returned
which slove ur issue.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|