Home c Find the entry of the substring in the line on the

Find the entry of the substring in the line on the

Author

Date

Category

Tell me please: There are two array of characters that are entered by the user, you must prevent them from checking them and find a substring in a row without using STRSTR, withdraw the index of the first entry, I can not think of the desired condition for the cycle.

Here is the code of what is ready, you need it only seems to be the correct condition:

int main ()
{
  CHAR STR1 [SIZE], STR2 [SIZE]; // declare arrays.
  PrintF ("Input String:");
  Fill_str (STR1); // Call the fill function for the first array (string).
  PrintF ("Input Pattern:");
  Fill_str (STR2); // Call the function of filling for the second array (substring).
  print_str (find_str (STR1, STR2)); // Output function with the argument of the returned value from the functions of the row comparison function.
  getch ();
  Return 0;
}
Void Fill_str (Char Str1 []) // Filling the array.
{
  GETS (STR1); // Get the user input to fill the array
}
INT FIND_STR (Char Str1 [], Char Str2 []) // Function for searching the string in the row.
{
  int index;
  // index = STRSTR (STR1, STR2); // Looking for the entry of the line 2 in line 1
  for ()
  {
    for ()
    {
    }
  }
  RETURN INDEX; // Return the index
}
Void Print_str (int index) // Output function.
{
  index == NULL? Printf ("Str1 Not In Str2"): PrintF ("Str1 in Str2, Entry Index Is:% d", index);
}

Answer 1, Authority 100%

for (i = 0; STR1 [i]! = '\ 0'; i ++) {
  For (j = i, k = 0; Str2 [k]! = '\ 0' & amp; & amp; str1 [j] == STR2 [K]; j ++, k ++)
   ;
  if (k & gt; 0 & amp; & amp; str2 [k] == '\ 0')
  {
   index = i;
   Break;
  }
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions