character strings

Thread Starter

sall

Joined Jul 13, 2011
10
Given a list of words we want to find all the words that end with a particular string which is stored in character array "endstr".For example "operating","ing" are valid inputs.For this we have a function "getword" which stores all the words in array wordlist that end with string stored in endstr into targetlist array.it is defined as under
Rich (BB code):
void getword (char wordlist [ ] [40], char endstr[],int n,char targetlist[ ][40) 

{ int i,count; 
  for(i=0;i<n;i++) 
{ if (            ) 
   {strcpy(targetlist[count],wordlist); 
   count++;}}  
what should be the condition written in if ( ) ?
 

cheezewizz

Joined Apr 16, 2009
82
don't take this the wrong way but the most important part of an education is learning how to learn if ya know what I mean. You need to able to find things out on your own without them being taught. Just nip along to http://www.cplusplus.com/reference/clibrary/cstring/strstr/ and read up a bit on it, I'm sure using their example there as a basis you could whip something up. If your teacher already has a solution in mind using a particular method, well, we've no idea what you've covered so far in your course so can't really guess as to what it could be.... good luck :D
 

Thread Starter

sall

Joined Jul 13, 2011
10
sir i went through strstr .there is this problem (as far as i understood) it will only tell me whether it is a substring or not.even if the string is a substring that will not necessarily entail that the string "ends" with that other string.i require a code in the if() that will test whether the string in the wordlist array ends with the string in endstr array.so strstr wont work i suppose.pls correct me if i am wrong.
 

BMorse

Joined Sep 26, 2009
2,675
You will have to write a small sub function that can compare the last three characters, with the search string characters, this function should return a boolean result, true if last 3 characters match the search string, false if not..... then in the If statement you could put a call to that function and check to see if returned value is true or false.
 

John P

Joined Oct 14, 2008
2,025
I'm a fool for doing this but:

Rich (BB code):
  // No, changed my mind. You should be the one to figure this out.
But I suggest that you consider a solution with a strcmp() and more than one strlen().
 
Last edited:
Top