please can any one write the code without using pointers and in a simplest way...
my question is finding substring position in main string .....these both strings you have to take at the run time and dont use any library methods.....you yourself have to write the code.....please give eply ASAP.....

8 Years
Discussion Span
Last Post by Adak

>>please can any one write the code without using pointers
I don't think that's possible.

Edited by Ancient Dragon: n/a


I would use logic like this:

[This is not "code", it's pseudo code, in C format. Difficult to describe it accurately, without code like syntax, imo.]

/* you can count these yourself, without using strlen(), if necessary */
lensub = strlen(substring);
lenstr = strlen(string);

for(i=0;i<(lenstr - lensub);i++) {  
  while(string[i] == substring[j] {
  /* now if --j == lensub  you've found a substring so
     break out of the for loop, or not, depending on 
     whether you want to find the first substring in the
     string, or find all the substrings in the string.

     decrement i, or you'll miss a letter in the string, if you're 
     searching for more substrings.

Certainly not as easy as using strstr()! ;)

Edited by Adak: n/a


Logic works OK, but don't decrement j. Using another variable like j, inside the while loop, makes it a bit easier.

sujathaarsid, be *sure* your next post in this thread shows your additional work on this program, not just "help". :)

Edited by Adak: n/a


remove "- lensub from the for loop

add "and j<lenstr" to the while test condition

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.