searching in a string a reversed string

Hi,
I am getting from a user 2 strings.
fisrt string let's say mystr1 and second mystr2.
now i need to find how many times mystr2 can be found in mystr1 but reversed.
example:
mystr1="hella, and goodbye and tralala"
mystr2="al".
as u can see i have "la" three times in mystr1.

can you help me please?

KinGuy
KinGuyAsked:
Who is Participating?
 
Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:
Ok,

I'm convinced.  Here's a sample code, thought it hasn't been tested.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define MAX_STRING_LENGTH 100

char BaseString[MAX_STRING_LENGTH+1];
char SubString[MAX_STRING_LENGTH+1];
char NewString[MAX_STRING_LENGTH+1];

main ()
{
  int    Length;
  int    idx;
  int    Count;
  char *cp;

/*  BaseString and SubString have been set by some process  */

/*  Reverse SubString into NewString  */

  Length = strlen (BaseString);
  for (idx = 0; idx < Length; idx++)
    NewString[Length - idx - 1] = SubString[Length];
  NewString[Length] = 0;

/*  Search BaseString for NewString, cpounting occurences  */

  Count = 0;
  for (cp = BaseString; cp;  cp = strstr (sp, NewString))
    Count++;

  fprintf (stdout, " %d occurences found.\n", Count);
}


Kent
0
 
Kent OlsenData Warehouse Architect / DBACommented:

Hi KinGuy,

I'd reverse the second string (into a third string) and then repeatedly call strstr() to see if it exists in the original string.


Kent
0
 
KinGuyAuthor Commented:
Kent, thank you for your comment, but can you write the whole program pleaze because i don't have c in my comp and i need the solution asap.

KinGuy
0
Firewall Management 201 with Professor Wool

In this whiteboard video, Professor Wool highlights the challenges, benefits and trade-offs of utilizing zero-touch automation for security policy change management. Watch and Learn!

 
Kent OlsenData Warehouse Architect / DBACommented:
Sorry KinGuy,

This sounds very much like a homework assignment and the rules of the board expressly forbid "academic dishonesty".  I'll gladly guide you to a solution, but I can't do it for you.


Kent
0
 
KinGuyAuthor Commented:
Hi Kent,
it is not homework, i need it for a project i am doing.

But i understand,
KinGuy
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi KinGuy,

I need more convincing.  If you can explain to me what the source code will do for you when you don't have a C compiler AND give me a better description of your project, I'll still be glad to help.


Kent
0
 
KinGuyAuthor Commented:
Hi Kent,

I am making a program that you enter a word and it will search for it in a text that you enter and i am doing this in hebrew. when i get text in heb from inet i somtimes get it reversed. so i want to be able to search for the correct word even if the whole text is reversed, i want to display how many times it occurs and where.

KinGuy
0
 
KinGuyAuthor Commented:
Thank you!

KinGuy
0
All Courses

From novice to tech pro — start learning today.