GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-May-2004, 16:58
sfeng12 sfeng12 is offline
New Member
 
Join Date: May 2004
Posts: 1
sfeng12 is on a distinguished road

string compare


let say,

you have
array=["how", "kick", "you"]
...code here.....
.
.
.

the program does is when user enter a string, such as "how he kick you"
then the program will compare the each word on the string to the array, check if they match.
like, it take "how" from string the user enter, and compare to array, see if it match to the array. if yes, check next word "he", so on.

anyone can help how to start programming this?
  #2  
Old 03-May-2004, 19:51
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
There are many ways to solve this task. Have you tried *anything*? Honestly, I don't really want to help you, because given your post, you don't appear to have actually attempted to solve the problem on your own. On the contrary, I do want to help you because this problem could drive you insane! You simply have to copy the user's input into a new array that looks like the one you already have, then compare each element in the input array to each other element in the first array for equality. If you are using an array of string objects, it may be useful for you to know that array subscripts work with string objects.
__________________
-Aaron
  #3  
Old 03-May-2004, 23:27
tay's Avatar
tay tay is offline
Junior Member
 
Join Date: Jan 2004
Posts: 77
tay will become famous soon enough
i simply code 1 for you
duno is that what you want or not

CPP / C++ / C Code:
#include <cstdlib>
#include <iostream>
#include <ctype.h>
using namespace std;
void convertToLowercase (char *sPtr)
{
 while (*sPtr != '\0')
 {
  if (*sPtr >= 'A' && *sPtr <= 'Z')
  {
   *sPtr = tolower(*sPtr);
  }
  ++sPtr;
 }
}
int main()
{
char how[4]="how";
char kick[5]="kick";
char you[4]="you";
char read[44];

cin.getline(read,44);
convertToLowercase(read);

string a=how;
string b=kick;
string c=you;

string full=a+" "+b+" "+c;

if(full==read)
cout<<"same"<<endl;
else
cout<<"Not same"<<endl;
    system("pause");
    return 0;
}
Last edited by dsmith : 04-May-2004 at 08:22. Reason: Please use [c] &[/c] for syntax highlighting
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Including Maps and strings?? maddie C++ Forum 17 05-Jul-2004 07:25
string comparison soccer022483 C++ Forum 2 21-Mar-2004 22:13
Speed up compare algorithm captnsaj C++ Forum 4 04-Feb-2004 15:50
[function] AutoLink (converts URLS into links inside a string) JdS PHP Code Library 0 26-Jan-2004 06:02
storing a token pointer as a string CoreLEx C Programming Language 1 07-Oct-2003 12:33

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:57.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.