|
|
|||||||
| Computers & Information Technologies « Everything related to computers and internet. » |
![]() |
|
|
Share | Thread Tools | Search this Thread |
|
|
#1 |
|
Vcoderz Team
Last Online: 08-23-2011
Join Date: May 2006
Posts: 134
Thanks: 81
Thanked 85 Times in 46 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
|
Hi, I just need some Help in C++. It has been long ago the last time I wrote a program. So I almost forgot everything.
1. So, I need a program that takes as input a STRING of characters (small letter), And TRANSFER IT INTO CAPITAL LETTERS. NOTE: I DO NOT need PRE DEFINED FUNCTIONS. IE: I do not want to use toUpper & toLower. (that's the main problem for me )It's OK if you want to use IsUpper & IsLower for checking (Boolean) only. 2. At the same program, I need another function that takes as input a string and try to search for a specific consicutive characters IE: I choose for example to search for the characters "ode" When the user input a string of characters: " I like vcoderz " for example, The output should be: ode is found. Else, nothing is found. I Hope I was clear in explaining the program I need. Hope somebody can help me. The first part is more Important to me (changing the letters) So PLZ TRY HARD TO HELP ME ![]() Thanks in advance!! GMA_FOR_EVER |
|
|
|
|
#2 |
|
Registered Member
Last Online: 09-05-2008
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 2 Times in 1 Post
Groans: 0
Groaned at 0 Times in 0 Posts
|
I made this for the 1st function you requested using C++.
Tested and working It transposes each small character into capital letter, and every other character remais the same. For ex: vcoderz -> VCODERZ v123Coderz -> V123CODERZ But didn't get the 2nd function. Code:
#include <iostream>
#include <string>
using namespace std;
#define N 0
int main()
{
char str[N]; //array or character forming a string
void small(char [] ); //calling the f*ckin function
cin >> str;
small(str);
system("pause");
}
void small(char text[])
{
char* t;
t = text;
while (*t != '\0') //While the character is not = end of string
{
if ((*t >= 97) && (*t <= 122))
{*t = *t - 32; //The difference between both capital
t++; //and small letters is 32 (A-a=32)
}
else t++;
} //Based on the ASCII table
cout << text << endl;
}
|
|
|
|
|
#3 |
|
Registered Member
Last Online: 09-05-2008
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 2 Times in 1 Post
Groans: 0
Groaned at 0 Times in 0 Posts
|
Here is your 2nd function
You can implement it the way it is in the program above Code:
//start function definition
void find(char text[],char ch )
{ char* t;
t = text;
bool found = 0;
while (*t != '\0' && !found)
if (*t == ch)
{cout << "Character '" << ch << "' found" ;
found =1;
}
else t++;
if (*t != ch)
cout << "Character '" << ch << "' not found" ;
}
__________________
We Do Not Worry About Warnings, We Only Care About Errors. Last edited by Moophz; 03-21-2007 at 06:07 PM. |
|
|
|
|
#4 |
|
Vcoderz Team
Last Online: 08-23-2011
Join Date: May 2006
Posts: 134
Thanks: 81
Thanked 85 Times in 46 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
|
Thank you Moophz very much... I really appretiate your help..
Hope everything will be ok. But I have a question: The first function, the compiler reads only till the first space, IE: It only reads the first word. So how can I let the function read all the string entered by the user ? I think that the while loop: ( while *t != '\0' ) should be changed, IE: we must change the '\0' into another character. Hope you can help me. Last edited by GMA_FOR_EVER; 03-21-2007 at 09:35 PM. |
|
|
|
|
#5 |
|
Registered Member
Last Online: 09-05-2008
Join Date: Mar 2007
Posts: 15
Thanks: 0
Thanked 2 Times in 1 Post
Groans: 0
Groaned at 0 Times in 0 Posts
|
No the \0 symbolises the end of the string, or last character in the array string
The main problem was when we used the 1st "cin >>" Code:
just replace cin >> str; (line 9) with cin.getline (str,256) ; Have a nice day.
__________________
We Do Not Worry About Warnings, We Only Care About Errors. Last edited by Moophz; 03-21-2007 at 11:09 PM. |
|
|
|
|
#6 |
|
Vcoderz Team
Last Online: 08-23-2011
Join Date: May 2006
Posts: 134
Thanks: 81
Thanked 85 Times in 46 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
|
AH OK MAN thx a lot ! It works
I Just need two more functions : 1. A fuction where you enter a string containing first name, middle name, last name : EX: IF the user entered: " John Albert Doe " The Output output should be: "Doe, John A". 2. A second funtion where the User ente a string And the Function should Check if the string is PALINDROM. Palindrom Means if you read the string from left or right it remains the same. EX: ABBA , 463364, MADAM, .... |
|
|
|
|
#7 |
|
Registered Member
Last Online: 02-14-2010
Join Date: Mar 2006
Posts: 846
Thanks: 71
Thanked 293 Times in 217 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
|
write your own code!!!......... w khaffif chwayyit colors thats creepy
__________________
--Capitalisation is the only difference between "I helped my uncle Jack off a horse" and "I helped my uncle jack off a horse" !! http://img482.imageshack.us/img482/4889/hell7ta.jpg Last edited by god; 03-22-2007 at 09:38 PM. |
|
|
![]() |
|
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|