| | |
Strings
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2006
Posts: 3
Reputation:
Solved Threads: 0
Hey,
I have to write a function that does this :
It checks if a word come up twice in a row .
For example :
myString[] = " Ariel lives in in the city city Ariel "
so now my function should print the words : in city .
because they are words that appear twice , notice that Ariel should not be printed because the word Ariel doesn't appear 1 after another.
pls help me solve this .
Thanks ahead ,
Nickol .
I have to write a function that does this :
It checks if a word come up twice in a row .
For example :
myString[] = " Ariel lives in in the city city Ariel "
so now my function should print the words : in city .
because they are words that appear twice , notice that Ariel should not be printed because the word Ariel doesn't appear 1 after another.
pls help me solve this .
Thanks ahead ,
Nickol .
No.
If you don't solve this problem yourself, you won't be solve the problem that comes after this one, or the problem that comes after that. You'll might be able to squeak by with a passing grade, but you'll have learned nothing.
If you don't solve this problem yourself, you won't be solve the problem that comes after this one, or the problem that comes after that. You'll might be able to squeak by with a passing grade, but you'll have learned nothing.
All my posts may be redistributed under the GNU Free Documentation License.
•
•
Join Date: Feb 2006
Posts: 3
Reputation:
Solved Threads: 0
I'm trying for 2 days to do so ..
But i'm so confused by the loops that i created .
Here's what i was trying to do :
const int SIZE=35;
int main()
{
int Length;
int counter=0;
char secString[SIZE];
char myString[SIZE] = "Ariel is in in the city city Ariel";
cout<<myString<<endl;
Length = strlen(myString);
cout<<"Length of the String is :"<<Length<<endl;
for (int i=0;i<Length;i++)
{
if (myString[i] == ' ')
for (int j=i;j>=0;j--)
{
secString[j] = myString[j];
cout<<"secString is : "<<secString<<endl;
}
counter++;
}
cout<<"You have "<<counter<<" Spaces in your String"<<endl;
cout<<"secString is : "<<secString<<endl;
return 0;
}
But i'm so confused by the loops that i created .
Here's what i was trying to do :
const int SIZE=35;
int main()
{
int Length;
int counter=0;
char secString[SIZE];
char myString[SIZE] = "Ariel is in in the city city Ariel";
cout<<myString<<endl;
Length = strlen(myString);
cout<<"Length of the String is :"<<Length<<endl;
for (int i=0;i<Length;i++)
{
if (myString[i] == ' ')
for (int j=i;j>=0;j--)
{
secString[j] = myString[j];
cout<<"secString is : "<<secString<<endl;
}
counter++;
}
cout<<"You have "<<counter<<" Spaces in your String"<<endl;
cout<<"secString is : "<<secString<<endl;
return 0;
}
Use [code] [/code] tags.
You can use C++-style strings and the find() function. Or you can use strstr(). Or you can stick with for loops.
Hint: ignore chars until you reach a space (or until isspace() (in <ctype.h>/<cctype>) returns non-zero).
You can use C++-style strings and the find() function. Or you can use strstr(). Or you can stick with for loops.
Hint: ignore chars until you reach a space (or until isspace() (in <ctype.h>/<cctype>) returns non-zero).
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
•
•
Join Date: Dec 2005
Posts: 43
Reputation:
Solved Threads: 0
Try something like this....
C++ Syntax (Toggle Plain Text)
<<sudocode>> first = true; In a for loop, using the char array... if (first) { build a string of chars in 'temp1' until there is a space and set first = false; } then build a string in 'temp2' until space. now compare temp1 to temp2. If they match, print temp1 copy temp2 into temp1 repeat }
![]() |
Similar Threads
- Comparing Strings in C# (C#)
- Please help me compare strings (Java)
- reversing two strings (C)
- C++ handling of strings in a boolean expression (C++)
- Compare strings... (C++)
- comparing two strings with linear search.. (Java)
- JSP and Oracle (JSP)
Other Threads in the C++ Forum
- Previous Thread: What am I doing wrong?
- Next Thread: System()
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






